From a8e2f3ebc9da60ef41459b080d8856d3cadf8c41 Mon Sep 17 00:00:00 2001 From: Shankar Singh C <83439957+ShankarSinghC@users.noreply.github.com> Date: Fri, 19 Jul 2024 14:01:11 +0530 Subject: [PATCH] refactor(connector): make the `original_authorized_amount` optional for MITs with `connector_mandate_details` (#5311) --- .../src/connector/cybersource/transformers.rs | 42 ++++++++++++------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/crates/router/src/connector/cybersource/transformers.rs b/crates/router/src/connector/cybersource/transformers.rs index 2f286964e3e..86960b43ca4 100644 --- a/crates/router/src/connector/cybersource/transformers.rs +++ b/crates/router/src/connector/cybersource/transformers.rs @@ -589,12 +589,30 @@ impl Some(payments::MandateReferenceId::ConnectorMandateId(_)) => { let original_amount = item .router_data - .get_recurring_mandate_payment_data()? - .get_original_payment_amount()?; + .recurring_mandate_payment_data + .as_ref() + .and_then(|recurring_mandate_payment_data| { + recurring_mandate_payment_data.original_payment_authorized_amount + }); + let original_currency = item .router_data - .get_recurring_mandate_payment_data()? - .get_original_payment_currency()?; + .recurring_mandate_payment_data + .as_ref() + .and_then(|recurring_mandate_payment_data| { + recurring_mandate_payment_data.original_payment_authorized_currency + }); + + let original_authorized_amount = match original_amount.zip(original_currency) { + Some((original_amount, original_currency)) => { + Some(utils::get_amount_as_string( + &api::CurrencyUnit::Base, + original_amount, + original_currency, + )?) + } + None => None, + }; ( None, None, @@ -602,11 +620,7 @@ impl initiator: None, merchant_intitiated_transaction: Some(MerchantInitiatedTransaction { reason: None, - original_authorized_amount: Some(utils::get_amount_as_string( - &api::CurrencyUnit::Base, - original_amount, - original_currency, - )?), + original_authorized_amount, previous_transaction_id: None, }), }), @@ -618,7 +632,8 @@ impl .map(|network| network.to_lowercase()) .as_deref() { - Some("discover") => { + //This is to make original_authorized_amount mandatory for discover card networks in NetworkMandateId flow + Some("004") => { let original_amount = Some( item.router_data .get_recurring_mandate_payment_data()? @@ -653,12 +668,11 @@ impl (original_amount, original_currency) } }; - - let original_authorized_amount = match (original_amount, original_currency) { - (Some(original_amount), Some(original_currency)) => Some( + let original_authorized_amount = match original_amount.zip(original_currency) { + Some((original_amount, original_currency)) => Some( utils::to_currency_base_unit(original_amount, original_currency)?, ), - _ => None, + None => None, }; commerce_indicator = "recurring".to_string(); (