From 6b9d025fe82ca0d532b334368eea06801a3c44ca Mon Sep 17 00:00:00 2001 From: Chikke Srujan Date: Fri, 18 Oct 2024 15:06:20 +0530 Subject: [PATCH] add support for 3ds mandates --- .../src/connectors/fiuu/transformers.rs | 34 +++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/crates/hyperswitch_connectors/src/connectors/fiuu/transformers.rs b/crates/hyperswitch_connectors/src/connectors/fiuu/transformers.rs index 2d158064e6ac..c9c9c2e25fe3 100644 --- a/crates/hyperswitch_connectors/src/connectors/fiuu/transformers.rs +++ b/crates/hyperswitch_connectors/src/connectors/fiuu/transformers.rs @@ -271,6 +271,8 @@ pub struct FiuuPaymentRequest { signature: Secret, #[serde(rename = "ReturnURL")] return_url: Option, + #[serde(rename = "NotificationURL")] + notification_url: Option, #[serde(flatten)] payment_method_data: FiuuPaymentMethodData, } @@ -401,6 +403,10 @@ impl TryFrom<&FiuuRouterData<&PaymentsAuthorizeRouterData>> for FiuuPaymentReque false => 1, true => 0, }; + let notification_url = Some( + Url::parse(&item.router_data.request.get_webhook_url()?) + .change_context(errors::ConnectorError::RequestEncodingFailed)?, + ); let payment_method_data = match item.router_data.request.payment_method_data { PaymentMethodData::Card(ref card) => { FiuuPaymentMethodData::try_from((card, item.router_data)) @@ -530,6 +536,7 @@ impl TryFrom<&FiuuRouterData<&PaymentsAuthorizeRouterData>> for FiuuPaymentReque return_url, payment_method_data, signature, + notification_url, }) } } @@ -714,7 +721,7 @@ pub struct NonThreeDSResponseData { pub error_desc: Option, } -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone)] pub struct ExtraParameters { token: Option>, } @@ -1162,6 +1169,27 @@ impl TryFrom> for PaymentsSy capture_method: item.data.request.capture_method, status: response.status, })?; + let mandate_reference = response.extra_parameters.as_ref().and_then(|extra_p| { + let mandate_token: Result = serde_json::from_str(extra_p); + match mandate_token { + Ok(token) => { + token.token.as_ref().map(|token| MandateReference { + connector_mandate_id: Some(token.clone().expose()), + payment_method_id: None, + mandate_metadata: None, + }) + } + Err(err) => { + router_env::logger::warn!( + "Failed to convert 'extraP' from fiuu webhook response to fiuu::ExtraParameters. \ + Input: '{}', Error: {}", + extra_p, + err + ); + None + } + } + }); let error_response = if status == enums::AttemptStatus::Failure { Some(ErrorResponse { status_code: item.http_code, @@ -1183,7 +1211,7 @@ impl TryFrom> for PaymentsSy let payments_response_data = PaymentsResponseData::TransactionResponse { resource_id: item.data.request.connector_transaction_id.clone(), redirection_data: None, - mandate_reference: None, + mandate_reference, connector_metadata: None, network_txn_id: None, connector_response_reference_id: None, @@ -1636,6 +1664,8 @@ pub struct FiuuWebhooksPaymentResponse { pub channel: String, pub error_desc: Option, pub error_code: Option, + #[serde(rename = "extraP")] + pub extra_parameters: Option, } #[derive(Debug, Deserialize, Serialize, Clone)]