From 5c4de8a5133c9a835d8c706c9b71bdfc8140568d Mon Sep 17 00:00:00 2001 From: Sakil Mostak <73734619+Sakilmostak@users.noreply.github.com> Date: Tue, 17 Dec 2024 19:19:56 +0530 Subject: [PATCH] fix(payment_methods): card_network and card_scheme should be consistent (#6849) --- crates/diesel_models/src/payment_method.rs | 18 +++++++++++++++++- .../router/src/core/payment_methods/cards.rs | 2 ++ .../router/src/core/payments/tokenization.rs | 10 +++++++++- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/crates/diesel_models/src/payment_method.rs b/crates/diesel_models/src/payment_method.rs index 46af78d6d91e..8ae34a6f89cf 100644 --- a/crates/diesel_models/src/payment_method.rs +++ b/crates/diesel_models/src/payment_method.rs @@ -219,6 +219,7 @@ pub enum PaymentMethodUpdate { }, UpdatePaymentMethodDataAndLastUsed { payment_method_data: Option, + scheme: Option, last_used_at: PrimitiveDateTime, }, PaymentMethodDataUpdate { @@ -264,6 +265,7 @@ pub enum PaymentMethodUpdate { pub enum PaymentMethodUpdate { UpdatePaymentMethodDataAndLastUsed { payment_method_data: Option, + scheme: Option, last_used_at: PrimitiveDateTime, }, PaymentMethodDataUpdate { @@ -395,6 +397,7 @@ pub struct PaymentMethodUpdateInternal { last_modified: PrimitiveDateTime, network_token_locker_id: Option, network_token_payment_method_data: Option, + scheme: Option, } #[cfg(all( @@ -419,6 +422,7 @@ impl PaymentMethodUpdateInternal { last_modified, network_token_locker_id, network_token_payment_method_data, + scheme, } = self; PaymentMethod { @@ -426,7 +430,7 @@ impl PaymentMethodUpdateInternal { merchant_id: source.merchant_id, payment_method_id: source.payment_method_id, accepted_currency: source.accepted_currency, - scheme: source.scheme, + scheme: scheme.or(source.scheme), token: source.token, cardholder_name: source.cardholder_name, issuer_name: source.issuer_name, @@ -489,6 +493,7 @@ impl From for PaymentMethodUpdateInternal { last_modified: common_utils::date_time::now(), network_token_locker_id: None, network_token_payment_method_data: None, + scheme: None, }, PaymentMethodUpdate::PaymentMethodDataUpdate { payment_method_data, @@ -508,6 +513,7 @@ impl From for PaymentMethodUpdateInternal { last_modified: common_utils::date_time::now(), network_token_locker_id: None, network_token_payment_method_data: None, + scheme: None, }, PaymentMethodUpdate::LastUsedUpdate { last_used_at } => Self { metadata: None, @@ -525,9 +531,11 @@ impl From for PaymentMethodUpdateInternal { last_modified: common_utils::date_time::now(), network_token_locker_id: None, network_token_payment_method_data: None, + scheme: None, }, PaymentMethodUpdate::UpdatePaymentMethodDataAndLastUsed { payment_method_data, + scheme, last_used_at, } => Self { metadata: None, @@ -545,6 +553,7 @@ impl From for PaymentMethodUpdateInternal { last_modified: common_utils::date_time::now(), network_token_locker_id: None, network_token_payment_method_data: None, + scheme, }, PaymentMethodUpdate::NetworkTransactionIdAndStatusUpdate { network_transaction_id, @@ -565,6 +574,7 @@ impl From for PaymentMethodUpdateInternal { last_modified: common_utils::date_time::now(), network_token_locker_id: None, network_token_payment_method_data: None, + scheme: None, }, PaymentMethodUpdate::StatusUpdate { status } => Self { metadata: None, @@ -582,6 +592,7 @@ impl From for PaymentMethodUpdateInternal { last_modified: common_utils::date_time::now(), network_token_locker_id: None, network_token_payment_method_data: None, + scheme: None, }, PaymentMethodUpdate::AdditionalDataUpdate { payment_method_data, @@ -609,6 +620,7 @@ impl From for PaymentMethodUpdateInternal { last_modified: common_utils::date_time::now(), network_token_locker_id, network_token_payment_method_data, + scheme: None, }, PaymentMethodUpdate::ConnectorMandateDetailsUpdate { connector_mandate_details, @@ -628,6 +640,7 @@ impl From for PaymentMethodUpdateInternal { last_modified: common_utils::date_time::now(), network_token_locker_id: None, network_token_payment_method_data: None, + scheme: None, }, PaymentMethodUpdate::NetworkTokenDataUpdate { network_token_requestor_reference_id, @@ -649,6 +662,7 @@ impl From for PaymentMethodUpdateInternal { network_token_requestor_reference_id, network_token_locker_id, network_token_payment_method_data, + scheme: None, }, PaymentMethodUpdate::ConnectorNetworkTransactionIdAndMandateDetailsUpdate { connector_mandate_details, @@ -670,6 +684,7 @@ impl From for PaymentMethodUpdateInternal { network_token_requestor_reference_id: None, network_token_locker_id: None, network_token_payment_method_data: None, + scheme: None, }, } } @@ -714,6 +729,7 @@ impl From for PaymentMethodUpdateInternal { PaymentMethodUpdate::UpdatePaymentMethodDataAndLastUsed { payment_method_data, last_used_at, + .. } => Self { payment_method_data, last_used_at: Some(last_used_at), diff --git a/crates/router/src/core/payment_methods/cards.rs b/crates/router/src/core/payment_methods/cards.rs index 9d8fbf58f5e7..e5e9ff92657a 100644 --- a/crates/router/src/core/payment_methods/cards.rs +++ b/crates/router/src/core/payment_methods/cards.rs @@ -2800,9 +2800,11 @@ pub async fn update_payment_method_and_last_used( pm: domain::PaymentMethod, payment_method_update: Option, storage_scheme: MerchantStorageScheme, + card_scheme: Option, ) -> errors::CustomResult<(), errors::VaultError> { let pm_update = payment_method::PaymentMethodUpdate::UpdatePaymentMethodDataAndLastUsed { payment_method_data: payment_method_update, + scheme: card_scheme, last_used_at: common_utils::date_time::now(), }; db.update_payment_method(&(state.into()), key_store, pm, pm_update, storage_scheme) diff --git a/crates/router/src/core/payments/tokenization.rs b/crates/router/src/core/payments/tokenization.rs index 89fb7752d1b0..94f221dd722f 100644 --- a/crates/router/src/core/payments/tokenization.rs +++ b/crates/router/src/core/payments/tokenization.rs @@ -549,8 +549,15 @@ where let existing_pm_data = payment_methods::cards::get_card_details_without_locker_fallback(&existing_pm,state) .await?; + // scheme should be updated in case of co-badged cards + let card_scheme = card + .card_network + .clone() + .map(|card_network| card_network.to_string()) + .or(existing_pm_data.scheme.clone()); + let updated_card = Some(CardDetailFromLocker { - scheme: existing_pm.scheme.clone(), + scheme: card_scheme.clone(), last4_digits: Some(card.card_number.get_last4()), issuer_country: card .card_issuing_country @@ -596,6 +603,7 @@ where existing_pm, pm_data_encrypted.map(Into::into), merchant_account.storage_scheme, + card_scheme, ) .await .change_context(errors::ApiErrorResponse::InternalServerError)