From fa1a33b8026969595dce8b3ea88361c09f953eb4 Mon Sep 17 00:00:00 2001 From: Sk Sakil Mostak Date: Mon, 16 Dec 2024 16:04:18 +0530 Subject: [PATCH 1/3] fix: card_network and card_scheme should be consistent --- crates/router/src/core/payment_methods/cards.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/crates/router/src/core/payment_methods/cards.rs b/crates/router/src/core/payment_methods/cards.rs index 135759611082..4a06cafe6194 100644 --- a/crates/router/src/core/payment_methods/cards.rs +++ b/crates/router/src/core/payment_methods/cards.rs @@ -5330,7 +5330,8 @@ pub async fn get_card_details_with_locker_fallback( }); Ok(if let Some(mut crd) = card_decrypted { - crd.scheme.clone_from(&pm.scheme); + let scheme = crd.card_network.clone().map(|cn| cn.to_string()); + crd.scheme.clone_from(&scheme); Some(crd) } else { logger::debug!( @@ -5359,7 +5360,8 @@ pub async fn get_card_details_without_locker_fallback( }); Ok(if let Some(mut crd) = card_decrypted { - crd.scheme.clone_from(&pm.scheme); + let scheme = crd.card_network.clone().map(|cn| cn.to_string()); + crd.scheme.clone_from(&scheme); crd } else { logger::debug!( From 99e7704a6be1a960e06fbc7fe67e18161ce93f7b Mon Sep 17 00:00:00 2001 From: Sk Sakil Mostak Date: Tue, 17 Dec 2024 16:55:35 +0530 Subject: [PATCH 2/3] fix: update card_scheme while saving cards --- crates/diesel_models/src/payment_method.rs | 16 +++++++++++++++- crates/router/src/core/payment_methods/cards.rs | 8 ++++---- crates/router/src/core/payments/tokenization.rs | 10 +++++++++- 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/crates/diesel_models/src/payment_method.rs b/crates/diesel_models/src/payment_method.rs index 206ba63e17fc..8c918ae0c60b 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 { @@ -395,6 +396,7 @@ pub struct PaymentMethodUpdateInternal { last_modified: PrimitiveDateTime, network_token_locker_id: Option, network_token_payment_method_data: Option, + scheme: Option, } #[cfg(all( @@ -419,6 +421,7 @@ impl PaymentMethodUpdateInternal { last_modified, network_token_locker_id, network_token_payment_method_data, + scheme, } = self; PaymentMethod { @@ -426,7 +429,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 +492,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 +512,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 +530,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 +552,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 +573,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 +591,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 +619,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 +639,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 +661,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 +683,7 @@ impl From for PaymentMethodUpdateInternal { network_token_requestor_reference_id: None, network_token_locker_id: None, network_token_payment_method_data: None, + scheme: None, }, } } diff --git a/crates/router/src/core/payment_methods/cards.rs b/crates/router/src/core/payment_methods/cards.rs index 4a06cafe6194..4dfaa9fccba6 100644 --- a/crates/router/src/core/payment_methods/cards.rs +++ b/crates/router/src/core/payment_methods/cards.rs @@ -2796,9 +2796,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) @@ -5330,8 +5332,7 @@ pub async fn get_card_details_with_locker_fallback( }); Ok(if let Some(mut crd) = card_decrypted { - let scheme = crd.card_network.clone().map(|cn| cn.to_string()); - crd.scheme.clone_from(&scheme); + crd.scheme.clone_from(&pm.scheme); Some(crd) } else { logger::debug!( @@ -5360,8 +5361,7 @@ pub async fn get_card_details_without_locker_fallback( }); Ok(if let Some(mut crd) = card_decrypted { - let scheme = crd.card_network.clone().map(|cn| cn.to_string()); - crd.scheme.clone_from(&scheme); + crd.scheme.clone_from(&pm.scheme); crd } else { logger::debug!( 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) From b086d964f685b0fc69d063d50e139e747358825f Mon Sep 17 00:00:00 2001 From: Sk Sakil Mostak Date: Tue, 17 Dec 2024 17:54:17 +0530 Subject: [PATCH 3/3] refactor: resolve v2 ci check --- crates/diesel_models/src/payment_method.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/crates/diesel_models/src/payment_method.rs b/crates/diesel_models/src/payment_method.rs index 1d76c1598a3e..8ae34a6f89cf 100644 --- a/crates/diesel_models/src/payment_method.rs +++ b/crates/diesel_models/src/payment_method.rs @@ -265,6 +265,7 @@ pub enum PaymentMethodUpdate { pub enum PaymentMethodUpdate { UpdatePaymentMethodDataAndLastUsed { payment_method_data: Option, + scheme: Option, last_used_at: PrimitiveDateTime, }, PaymentMethodDataUpdate { @@ -728,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),