Skip to content

Commit

Permalink
fix(payment_methods): card_network and card_scheme should be consiste…
Browse files Browse the repository at this point in the history
…nt (#6849)
  • Loading branch information
Sakilmostak authored Dec 17, 2024
1 parent 107098c commit 5c4de8a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
18 changes: 17 additions & 1 deletion crates/diesel_models/src/payment_method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ pub enum PaymentMethodUpdate {
},
UpdatePaymentMethodDataAndLastUsed {
payment_method_data: Option<Encryption>,
scheme: Option<String>,
last_used_at: PrimitiveDateTime,
},
PaymentMethodDataUpdate {
Expand Down Expand Up @@ -264,6 +265,7 @@ pub enum PaymentMethodUpdate {
pub enum PaymentMethodUpdate {
UpdatePaymentMethodDataAndLastUsed {
payment_method_data: Option<Encryption>,
scheme: Option<String>,
last_used_at: PrimitiveDateTime,
},
PaymentMethodDataUpdate {
Expand Down Expand Up @@ -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(
Expand All @@ -419,14 +422,15 @@ impl PaymentMethodUpdateInternal {
last_modified,
network_token_locker_id,
network_token_payment_method_data,
scheme,
} = self;

PaymentMethod {
customer_id: source.customer_id,
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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
},
}
}
Expand Down Expand Up @@ -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),
Expand Down
2 changes: 2 additions & 0 deletions crates/router/src/core/payment_methods/cards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 9 additions & 1 deletion crates/router/src/core/payments/tokenization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 5c4de8a

Please sign in to comment.