Skip to content

Commit 6230eb4

Browse files
fix(payments): populate payment_method_type in payment_attempt for cards (#6557)
Co-authored-by: Kashif <[email protected]>
1 parent d927598 commit 6230eb4

File tree

3 files changed

+51
-6
lines changed

3 files changed

+51
-6
lines changed

crates/router/src/core/payments/operations/payment_confirm.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -576,12 +576,6 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Pa
576576
payment_method_info,
577577
} = mandate_details;
578578

579-
payment_attempt.payment_method_type = payment_method_type
580-
.or(payment_attempt.payment_method_type)
581-
.or(payment_method_info
582-
.as_ref()
583-
.and_then(|pm_info| pm_info.payment_method_type));
584-
585579
let token = token.or_else(|| payment_attempt.payment_token.clone());
586580

587581
helpers::validate_pm_or_token_given(
@@ -650,6 +644,17 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Pa
650644

651645
payment_attempt.payment_method = payment_method.or(payment_attempt.payment_method);
652646

647+
let payment_method_type = Option::<api_models::enums::PaymentMethodType>::foreign_from((
648+
payment_method_type,
649+
additional_pm_data.as_ref(),
650+
));
651+
652+
payment_attempt.payment_method_type = payment_method_type
653+
.or(payment_attempt.payment_method_type)
654+
.or(payment_method_info
655+
.as_ref()
656+
.and_then(|pm_info| pm_info.payment_method_type));
657+
653658
// The operation merges mandate data from both request and payment_attempt
654659
let setup_mandate = mandate_data.map(|mut sm| {
655660
sm.mandate_type = payment_attempt.mandate_details.clone().or(sm.mandate_type);

crates/router/src/core/payments/operations/payment_create.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,6 +1195,11 @@ impl PaymentCreate {
11951195
None
11961196
};
11971197

1198+
let payment_method_type = Option::<enums::PaymentMethodType>::foreign_from((
1199+
payment_method_type,
1200+
additional_pm_data.as_ref(),
1201+
));
1202+
11981203
Ok((
11991204
storage::PaymentAttemptNew {
12001205
payment_id: payment_id.to_owned(),

crates/router/src/core/payments/transformers.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3602,3 +3602,38 @@ impl ForeignFrom<ConnectorMandateReferenceId> for DieselConnectorMandateReferenc
36023602
}
36033603
}
36043604
}
3605+
3606+
impl ForeignFrom<(Self, Option<&api_models::payments::AdditionalPaymentData>)>
3607+
for Option<enums::PaymentMethodType>
3608+
{
3609+
fn foreign_from(req: (Self, Option<&api_models::payments::AdditionalPaymentData>)) -> Self {
3610+
let (payment_method_type, additional_pm_data) = req;
3611+
additional_pm_data
3612+
.and_then(|pm_data| {
3613+
if let api_models::payments::AdditionalPaymentData::Card(card_info) = pm_data {
3614+
card_info.card_type.as_ref().and_then(|card_type_str| {
3615+
api_models::enums::PaymentMethodType::from_str(&card_type_str.to_lowercase()).map_err(|err| {
3616+
crate::logger::error!(
3617+
"Err - {:?}\nInvalid card_type value found in BIN DB - {:?}",
3618+
err,
3619+
card_type_str,
3620+
);
3621+
}).ok()
3622+
})
3623+
} else {
3624+
None
3625+
}
3626+
})
3627+
.map_or(payment_method_type, |card_type_in_bin_store| {
3628+
if let Some(card_type_in_req) = payment_method_type {
3629+
if card_type_in_req != card_type_in_bin_store {
3630+
crate::logger::info!(
3631+
"Mismatch in card_type\nAPI request - {}; BIN lookup - {}\nOverriding with {}",
3632+
card_type_in_req, card_type_in_bin_store, card_type_in_bin_store,
3633+
);
3634+
}
3635+
}
3636+
Some(card_type_in_bin_store)
3637+
})
3638+
}
3639+
}

0 commit comments

Comments
 (0)