Skip to content

Commit

Permalink
fix(webhooks): add support for updating mandate details in webhooks f…
Browse files Browse the repository at this point in the history
…low (#6523)

Co-authored-by: Chikke Srujan <[email protected]>
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored and Chikke Srujan committed Nov 13, 2024
1 parent 596c49e commit 52b0e63
Show file tree
Hide file tree
Showing 9 changed files with 400 additions and 36 deletions.
122 changes: 121 additions & 1 deletion crates/diesel_models/src/payment_attempt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,10 @@ pub enum PaymentAttemptUpdate {
payment_method_id: Option<String>,
updated_by: String,
},
ConnectorMandateDetailUpdate {
connector_mandate_detail: Option<ConnectorMandateReferenceId>,
updated_by: String,
},
BlocklistUpdate {
status: storage_enums::AttemptStatus,
error_code: Option<Option<String>>,
Expand Down Expand Up @@ -628,6 +632,10 @@ pub enum PaymentAttemptUpdate {
// payment_method_id: Option<String>,
// updated_by: String,
// },
// ConnectorMandateDetailUpdate {
// connector_mandate_detail: Option<ConnectorMandateReferenceId>,
// updated_by: String,
// }
// BlocklistUpdate {
// status: storage_enums::AttemptStatus,
// error_code: Option<Option<String>>,
Expand Down Expand Up @@ -1393,7 +1401,63 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
// customer_acceptance: None,
// card_network: None,
// },
// PaymentAttemptUpdate::PaymentMethodDetailsUpdate {
// PaymentAttemptUpdate::ConnectorMandateDetailUpdate {
// connector_mandate_detail,
// updated_by,
// } => Self {
// payment_method_id: None,
// modified_at: common_utils::date_time::now(),
// updated_by,
// amount: None,
// net_amount: None,
// currency: None,
// status: None,
// connector_transaction_id: None,
// amount_to_capture: None,
// connector: None,
// authentication_type: None,
// payment_method: None,
// error_message: None,
// cancellation_reason: None,
// mandate_id: None,
// browser_info: None,
// payment_token: None,
// error_code: None,
// connector_metadata: None,
// payment_method_data: None,
// payment_method_type: None,
// payment_experience: None,
// business_sub_label: None,
// straight_through_algorithm: None,
// preprocessing_step_id: None,
// error_reason: None,
// capture_method: None,
// connector_response_reference_id: None,
// multiple_capture_count: None,
// surcharge_amount: None,
// tax_amount: None,
// amount_capturable: None,
// merchant_connector_id: None,
// authentication_data: None,
// encoded_data: None,
// unified_code: None,
// unified_message: None,
// external_three_ds_authentication_attempted: None,
// authentication_connector: None,
// authentication_id: None,
// fingerprint_id: None,
// payment_method_billing_address_id: None,
// charge_id: None,
// client_source: None,
// client_version: None,
// customer_acceptance: None,
// card_network: None,
// shipping_cost: None,
// order_tax_amount: None,
// connector_transaction_data: None,
// connector_mandate_detail,
// },
// PaymentAttemptUpdate::ConnectorMandateDetailUpdate {
// payment_method_id,
// updated_by,
// } => Self {
Expand Down Expand Up @@ -2394,6 +2458,62 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
connector_transaction_data: None,
connector_mandate_detail: None,
},
PaymentAttemptUpdate::ConnectorMandateDetailUpdate {
connector_mandate_detail,
updated_by,
} => Self {
payment_method_id: None,
modified_at: common_utils::date_time::now(),
updated_by,
amount: None,
net_amount: None,
currency: None,
status: None,
connector_transaction_id: None,
amount_to_capture: None,
connector: None,
authentication_type: None,
payment_method: None,
error_message: None,
cancellation_reason: None,
mandate_id: None,
browser_info: None,
payment_token: None,
error_code: None,
connector_metadata: None,
payment_method_data: None,
payment_method_type: None,
payment_experience: None,
business_sub_label: None,
straight_through_algorithm: None,
preprocessing_step_id: None,
error_reason: None,
capture_method: None,
connector_response_reference_id: None,
multiple_capture_count: None,
surcharge_amount: None,
tax_amount: None,
amount_capturable: None,
merchant_connector_id: None,
authentication_data: None,
encoded_data: None,
unified_code: None,
unified_message: None,
external_three_ds_authentication_attempted: None,
authentication_connector: None,
authentication_id: None,
fingerprint_id: None,
payment_method_billing_address_id: None,
charge_id: None,
client_source: None,
client_version: None,
customer_acceptance: None,
card_network: None,
shipping_cost: None,
order_tax_amount: None,
connector_transaction_data: None,
connector_mandate_detail,
},
PaymentAttemptUpdate::PaymentMethodDetailsUpdate {
payment_method_id,
updated_by,
Expand Down
34 changes: 33 additions & 1 deletion crates/hyperswitch_connectors/src/connectors/fiuu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ use masking::{ExposeInterface, PeekInterface, Secret};
use reqwest::multipart::Form;
use serde::{Deserialize, Serialize};
use serde_json::Value;
use transformers::{self as fiuu, FiuuWebhooksResponse};
use transformers::{self as fiuu, ExtraParameters, FiuuWebhooksResponse};

use crate::{
constants::headers,
Expand Down Expand Up @@ -890,4 +890,36 @@ impl webhooks::IncomingWebhook for Fiuu {
}
}
}

fn get_mandate_details(
&self,
request: &webhooks::IncomingWebhookRequestDetails<'_>,
) -> CustomResult<
Option<hyperswitch_domain_models::router_flow_types::ConnectorMandateDetails>,
errors::ConnectorError,
> {
let webhook_payment_response: transformers::FiuuWebhooksPaymentResponse =
serde_urlencoded::from_bytes::<transformers::FiuuWebhooksPaymentResponse>(request.body)
.change_context(errors::ConnectorError::WebhookResourceObjectNotFound)?;
let mandate_reference = webhook_payment_response.extra_parameters.as_ref().and_then(|extra_p| {
let mandate_token: Result<ExtraParameters, _> = serde_json::from_str(extra_p);
match mandate_token {
Ok(token) => {
token.token.as_ref().map(|token| hyperswitch_domain_models::router_flow_types::ConnectorMandateDetails {
connector_mandate_id:token.clone(),
})
}
Err(err) => {
router_env::logger::warn!(
"Failed to convert 'extraP' from fiuu webhook response to fiuu::ExtraParameters. \
Input: '{}', Error: {}",
extra_p,
err
);
None
}
}
});
Ok(mandate_reference)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,7 @@ pub struct NonThreeDSResponseData {

#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct ExtraParameters {
token: Option<Secret<String>>,
pub token: Option<Secret<String>>,
}

impl<F>
Expand Down
11 changes: 11 additions & 0 deletions crates/hyperswitch_domain_models/src/payments/payment_attempt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -807,6 +807,10 @@ pub enum PaymentAttemptUpdate {
payment_method_id: Option<String>,
updated_by: String,
},
ConnectorMandateDetailUpdate {
connector_mandate_detail: Option<ConnectorMandateReferenceId>,
updated_by: String,
},
VoidUpdate {
status: storage_enums::AttemptStatus,
cancellation_reason: Option<String>,
Expand Down Expand Up @@ -994,6 +998,13 @@ impl PaymentAttemptUpdate {
error_message,
updated_by,
},
Self::ConnectorMandateDetailUpdate {
connector_mandate_detail,
updated_by,
} => DieselPaymentAttemptUpdate::ConnectorMandateDetailUpdate {
connector_mandate_detail,
updated_by,
},
Self::PaymentMethodDetailsUpdate {
payment_method_id,
updated_by,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
use serde::Serialize;

#[derive(Clone, Debug)]
pub struct VerifyWebhookSource;

#[derive(Debug, Clone, Serialize)]
pub struct ConnectorMandateDetails {
pub connector_mandate_id: masking::Secret<String>,
}
11 changes: 11 additions & 0 deletions crates/hyperswitch_interfaces/src/webhooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,4 +226,15 @@ pub trait IncomingWebhook: ConnectorCommon + Sync {
)
.into())
}

/// fn get_mandate_details
fn get_mandate_details(
&self,
_request: &IncomingWebhookRequestDetails<'_>,
) -> CustomResult<
Option<hyperswitch_domain_models::router_flow_types::ConnectorMandateDetails>,
errors::ConnectorError,
> {
Ok(None)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1424,15 +1424,6 @@ impl Default for settings::RequiredFields {
value: None,
}
),
(
"billing.address.last_name".to_string(),
RequiredFieldInfo {
required_field: "payment_method_data.billing.address.last_name".to_string(),
display_name: "card_holder_name".to_string(),
field_type: enums::FieldType::UserFullName,
value: None,
}
),
]),
non_mandate: HashMap::new(),
common: HashMap::from(
Expand Down Expand Up @@ -4544,15 +4535,6 @@ impl Default for settings::RequiredFields {
value: None,
}
),
(
"billing.address.last_name".to_string(),
RequiredFieldInfo {
required_field: "payment_method_data.billing.address.last_name".to_string(),
display_name: "card_holder_name".to_string(),
field_type: enums::FieldType::UserFullName,
value: None,
}
),
]),
non_mandate: HashMap::new(),
common: HashMap::from(
Expand Down
Loading

0 comments on commit 52b0e63

Please sign in to comment.