From 8150f3115060025e44864d785491012dec54dd97 Mon Sep 17 00:00:00 2001 From: awasthi21 <107559116+awasthi21@users.noreply.github.com> Date: Wed, 6 Nov 2024 22:44:03 +0530 Subject: [PATCH] fix(core): PMD Not Getting Populated for Saved Card Transactions (#6497) --- .../src/connector/paybox/transformers.rs | 11 ++- .../payments/operations/payment_confirm.rs | 70 +++++++++---------- 2 files changed, 45 insertions(+), 36 deletions(-) diff --git a/crates/router/src/connector/paybox/transformers.rs b/crates/router/src/connector/paybox/transformers.rs index 4e1270f419c8..27096c2a63b5 100644 --- a/crates/router/src/connector/paybox/transformers.rs +++ b/crates/router/src/connector/paybox/transformers.rs @@ -1109,7 +1109,16 @@ impl TryFrom<&PayboxRouterData<&types::PaymentsCompleteAuthorizeRouterData>> for |data| Some(data.clone()), ), customer_id: match item.router_data.request.is_mandate_payment() { - true => Some(Secret::new(item.router_data.payment_id.clone())), + true => { + let reference_id = item + .router_data + .connector_mandate_request_reference_id + .clone() + .ok_or_else(|| errors::ConnectorError::MissingRequiredField { + field_name: "connector_mandate_request_reference_id", + })?; + Some(Secret::new(reference_id)) + } false => None, }, }) diff --git a/crates/router/src/core/payments/operations/payment_confirm.rs b/crates/router/src/core/payments/operations/payment_confirm.rs index 1bd3ddce7351..635b3c24cf21 100644 --- a/crates/router/src/core/payments/operations/payment_confirm.rs +++ b/crates/router/src/core/payments/operations/payment_confirm.rs @@ -576,41 +576,6 @@ impl GetTracker, api::PaymentsRequest> for Pa payment_method_info, } = mandate_details; - let additional_pm_data_from_locker = if let Some(ref pm) = payment_method_info { - let card_detail_from_locker: Option = pm - .payment_method_data - .clone() - .map(|x| x.into_inner().expose()) - .and_then(|v| { - v.parse_value("PaymentMethodsData") - .map_err(|err| { - router_env::logger::info!( - "PaymentMethodsData deserialization failed: {:?}", - err - ) - }) - .ok() - }) - .and_then(|pmd| match pmd { - PaymentMethodsData::Card(crd) => Some(api::CardDetailFromLocker::from(crd)), - _ => None, - }); - card_detail_from_locker.map(|card_details| { - let additional_data = card_details.into(); - api_models::payments::AdditionalPaymentData::Card(Box::new(additional_data)) - }) - } else { - None - }; - payment_attempt.payment_method_data = additional_pm_data_from_locker - .as_ref() - .map(Encode::encode_to_value) - .transpose() - .change_context(errors::ApiErrorResponse::InternalServerError) - .attach_printable("Failed to encode additional pm data")?; - - payment_attempt.payment_method = payment_method.or(payment_attempt.payment_method); - payment_attempt.payment_method_type = payment_method_type .or(payment_attempt.payment_method_type) .or(payment_method_info @@ -650,6 +615,41 @@ impl GetTracker, api::PaymentsRequest> for Pa } else { (None, payment_method_info) }; + let additional_pm_data_from_locker = if let Some(ref pm) = payment_method_info { + let card_detail_from_locker: Option = pm + .payment_method_data + .clone() + .map(|x| x.into_inner().expose()) + .and_then(|v| { + v.parse_value("PaymentMethodsData") + .map_err(|err| { + router_env::logger::info!( + "PaymentMethodsData deserialization failed: {:?}", + err + ) + }) + .ok() + }) + .and_then(|pmd| match pmd { + PaymentMethodsData::Card(crd) => Some(api::CardDetailFromLocker::from(crd)), + _ => None, + }); + card_detail_from_locker.map(|card_details| { + let additional_data = card_details.into(); + api_models::payments::AdditionalPaymentData::Card(Box::new(additional_data)) + }) + } else { + None + }; + payment_attempt.payment_method_data = additional_pm_data_from_locker + .as_ref() + .map(Encode::encode_to_value) + .transpose() + .change_context(errors::ApiErrorResponse::InternalServerError) + .attach_printable("Failed to encode additional pm data")?; + + payment_attempt.payment_method = payment_method.or(payment_attempt.payment_method); + // The operation merges mandate data from both request and payment_attempt let setup_mandate = mandate_data.map(|mut sm| { sm.mandate_type = payment_attempt.mandate_details.clone().or(sm.mandate_type);