-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
fix(router): update nick_name only if card_token.card_holder_name is non empty and populate additional card_details from payment_attempt if not present in the locker #6308
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1709,6 +1709,7 @@ pub async fn retrieve_payment_method_with_temporary_token( | |
state: &SessionState, | ||
token: &str, | ||
payment_intent: &PaymentIntent, | ||
payment_attempt: &PaymentAttempt, | ||
merchant_key_store: &domain::MerchantKeyStore, | ||
card_token_data: Option<&domain::CardToken>, | ||
) -> RouterResult<Option<(domain::PaymentMethodData, enums::PaymentMethod)>> { | ||
|
@@ -1735,12 +1736,15 @@ pub async fn retrieve_payment_method_with_temporary_token( | |
|
||
// The card_holder_name from locker retrieved card is considered if it is a non-empty string or else card_holder_name is picked | ||
// from payment_method_data.card_token object | ||
let name_on_card = card_token_data.and_then(|token_data| { | ||
is_card_updated = true; | ||
token_data.card_holder_name.clone() | ||
}); | ||
let name_on_card = | ||
card_token_data.and_then(|token_data| token_data.card_holder_name.clone()); | ||
|
||
updated_card.nick_name = name_on_card; | ||
if let Some(name) = name_on_card.clone() { | ||
if !name.peek().is_empty() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we do trim here? |
||
is_card_updated = true; | ||
updated_card.nick_name = name_on_card; | ||
} | ||
} | ||
|
||
if let Some(token_data) = card_token_data { | ||
if let Some(cvc) = token_data.card_cvc.clone() { | ||
|
@@ -1749,6 +1753,38 @@ pub async fn retrieve_payment_method_with_temporary_token( | |
} | ||
} | ||
|
||
// populate additional card details from payment_attempt.payment_method_data (additional_payment_data) if not present in the locker | ||
if updated_card.card_issuer.is_none() | ||
|| updated_card.card_network.is_none() | ||
|| updated_card.card_type.is_none() | ||
|| updated_card.card_issuing_country.is_none() | ||
{ | ||
let additional_payment_method_data: Option< | ||
api_models::payments::AdditionalPaymentData, | ||
> = payment_attempt | ||
.payment_method_data | ||
.clone() | ||
.and_then(|data| match data { | ||
serde_json::Value::Null => None, // This is to handle the case when the payment_method_data is null | ||
_ => Some(data.parse_value("AdditionalPaymentData")), | ||
}) | ||
.transpose() | ||
.map_err(|err| logger::error!("Failed to parse AdditionalPaymentData {err:?}")) | ||
.ok() | ||
.flatten(); | ||
if let Some(api_models::payments::AdditionalPaymentData::Card(card)) = | ||
additional_payment_method_data | ||
{ | ||
is_card_updated = true; | ||
updated_card.card_issuer = updated_card.card_issuer.or(card.card_issuer); | ||
updated_card.card_network = updated_card.card_network.or(card.card_network); | ||
updated_card.card_type = updated_card.card_type.or(card.card_type); | ||
updated_card.card_issuing_country = updated_card | ||
.card_issuing_country | ||
.or(card.card_issuing_country); | ||
}; | ||
}; | ||
|
||
if is_card_updated { | ||
let updated_pm = domain::PaymentMethodData::Card(updated_card); | ||
vault::Vault::store_payment_method_data_in_locker( | ||
|
@@ -2278,6 +2314,7 @@ pub async fn make_pm_data<'a, F: Clone, R, D>( | |
merchant_key_store, | ||
hyperswitch_token, | ||
&payment_data.payment_intent, | ||
&payment_data.payment_attempt, | ||
card_token_data.as_ref(), | ||
customer, | ||
storage_scheme, | ||
|
@@ -4296,7 +4333,7 @@ pub async fn get_additional_payment_data( | |
api_models::payments::AdditionalPaymentData::Card(Box::new( | ||
api_models::payments::AdditionalCardInfo { | ||
card_issuer: card_info.card_issuer, | ||
card_network, | ||
card_network: card_info.card_network, | ||
bank_code: card_info.bank_code, | ||
card_type: card_info.card_type, | ||
card_issuing_country: card_info.card_issuing_country, | ||
|
@@ -5637,6 +5674,7 @@ pub async fn get_payment_method_details_from_payment_token( | |
state, | ||
&generic_token.token, | ||
payment_intent, | ||
payment_attempt, | ||
key_store, | ||
None, | ||
) | ||
|
@@ -5648,6 +5686,7 @@ pub async fn get_payment_method_details_from_payment_token( | |
state, | ||
&generic_token.token, | ||
payment_intent, | ||
payment_attempt, | ||
key_store, | ||
None, | ||
) | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clone not required