Skip to content

Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation

fix(payment_methods): card_network and card_scheme should be consistent (#6849)

Sakil Mostak5c4de8a5133c
diff --git a/crates/diesel_models/src/payment_method.rs b/crates/diesel_models/src/payment_method.rs
index 46af78d6d9..8ae34a6f89 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<Encryption>,
+ scheme: Option<String>,
last_used_at: PrimitiveDateTime,
},
PaymentMethodDataUpdate {
@@ -264,6 +265,7 @@ pub enum PaymentMethodUpdate {
pub enum PaymentMethodUpdate {
UpdatePaymentMethodDataAndLastUsed {
payment_method_data: Option<Encryption>,
+ scheme: Option<String>,
last_used_at: PrimitiveDateTime,
},
PaymentMethodDataUpdate {
@@ -395,6 +397,7 @@ pub struct PaymentMethodUpdateInternal {
last_modified: PrimitiveDateTime,
network_token_locker_id: Option<String>,
network_token_payment_method_data: Option<Encryption>,
+ scheme: Option<String>,
}
#[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<PaymentMethodUpdate> 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<PaymentMethodUpdate> 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<PaymentMethodUpdate> 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<PaymentMethodUpdate> 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<PaymentMethodUpdate> 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<PaymentMethodUpdate> 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<PaymentMethodUpdate> 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<PaymentMethodUpdate> 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<PaymentMethodUpdate> 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<PaymentMethodUpdate> 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<PaymentMethodUpdate> 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 9d8fbf58f5..e5e9ff9265 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<Encryption>,
storage_scheme: MerchantStorageScheme,
+ card_scheme: Option<String>,
) -> 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 89fb7752d1..94f221dd72 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)