Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(payment_methods): use existing field value of nick_name in db if not sent during request #5105

Merged
merged 1 commit into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions crates/router/src/core/payment_methods/cards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -656,21 +656,32 @@ pub async fn add_payment_method(
.attach_printable("Failed while updating card metadata changes"))?
};

let existing_pm_data = get_card_details_without_locker_fallback(
&existing_pm,
key_store.key.peek(),
&state,
)
.await?;

let updated_card = Some(api::CardDetailFromLocker {
scheme: existing_pm.scheme.clone(),
last4_digits: Some(card.card_number.get_last4()),
issuer_country: card.card_issuing_country,
issuer_country: card
.card_issuing_country
.or(existing_pm_data.issuer_country),
card_isin: Some(card.card_number.get_card_isin()),
card_number: Some(card.card_number),
expiry_month: Some(card.card_exp_month),
expiry_year: Some(card.card_exp_year),
card_token: None,
card_fingerprint: None,
card_holder_name: card.card_holder_name,
nick_name: card.nick_name,
card_network: card.card_network,
card_issuer: card.card_issuer,
card_type: card.card_type,
card_holder_name: card
.card_holder_name
.or(existing_pm_data.card_holder_name),
nick_name: card.nick_name.or(existing_pm_data.nick_name),
card_network: card.card_network.or(existing_pm_data.card_network),
card_issuer: card.card_issuer.or(existing_pm_data.card_issuer),
card_type: card.card_type.or(existing_pm_data.card_type),
saved_to_locker: true,
});

Expand Down
27 changes: 20 additions & 7 deletions crates/router/src/core/payments/tokenization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use common_utils::{
id_type, pii,
};
use error_stack::{report, ResultExt};
use masking::ExposeInterface;
use masking::{ExposeInterface, PeekInterface};
use router_env::{instrument, metrics::add_attributes, tracing};

use super::helpers;
Expand Down Expand Up @@ -468,21 +468,34 @@ where
))?
};

let existing_pm_data = payment_methods::cards::get_card_details_without_locker_fallback(
&existing_pm,
key_store.key.peek(),
state,
)
.await?;

let updated_card = Some(CardDetailFromLocker {
scheme: existing_pm.scheme.clone(),
last4_digits: Some(card.card_number.get_last4()),
issuer_country: card.card_issuing_country,
issuer_country: card
.card_issuing_country
.or(existing_pm_data.issuer_country),
card_isin: Some(card.card_number.get_card_isin()),
card_number: Some(card.card_number),
expiry_month: Some(card.card_exp_month),
expiry_year: Some(card.card_exp_year),
card_token: None,
card_fingerprint: None,
card_holder_name: card.card_holder_name,
nick_name: card.nick_name,
card_network: card.card_network,
card_issuer: card.card_issuer,
card_type: card.card_type,
card_holder_name: card
.card_holder_name
.or(existing_pm_data.card_holder_name),
nick_name: card.nick_name.or(existing_pm_data.nick_name),
card_network: card
.card_network
.or(existing_pm_data.card_network),
card_issuer: card.card_issuer.or(existing_pm_data.card_issuer),
card_type: card.card_type.or(existing_pm_data.card_type),
saved_to_locker: true,
});

Expand Down
Loading