Skip to content

Commit

Permalink
fix(payments): populate payment_method_type in payment_attempt for ca…
Browse files Browse the repository at this point in the history
…rds (#6557)

Co-authored-by: Kashif <kashif.dev@protonmail.com>
  • Loading branch information
srujanchikke and kashif-m authored Nov 13, 2024
1 parent d927598 commit 6230eb4
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 6 deletions.
17 changes: 11 additions & 6 deletions crates/router/src/core/payments/operations/payment_confirm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -576,12 +576,6 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Pa
payment_method_info,
} = mandate_details;

payment_attempt.payment_method_type = payment_method_type
.or(payment_attempt.payment_method_type)
.or(payment_method_info
.as_ref()
.and_then(|pm_info| pm_info.payment_method_type));

let token = token.or_else(|| payment_attempt.payment_token.clone());

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

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

let payment_method_type = Option::<api_models::enums::PaymentMethodType>::foreign_from((
payment_method_type,
additional_pm_data.as_ref(),
));

payment_attempt.payment_method_type = payment_method_type
.or(payment_attempt.payment_method_type)
.or(payment_method_info
.as_ref()
.and_then(|pm_info| pm_info.payment_method_type));

// The operation merges mandate data from both request and payment_attempt
let setup_mandate = mandate_data.map(|mut sm| {
sm.mandate_type = payment_attempt.mandate_details.clone().or(sm.mandate_type);
Expand Down
5 changes: 5 additions & 0 deletions crates/router/src/core/payments/operations/payment_create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1195,6 +1195,11 @@ impl PaymentCreate {
None
};

let payment_method_type = Option::<enums::PaymentMethodType>::foreign_from((
payment_method_type,
additional_pm_data.as_ref(),
));

Ok((
storage::PaymentAttemptNew {
payment_id: payment_id.to_owned(),
Expand Down
35 changes: 35 additions & 0 deletions crates/router/src/core/payments/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3602,3 +3602,38 @@ impl ForeignFrom<ConnectorMandateReferenceId> for DieselConnectorMandateReferenc
}
}
}

impl ForeignFrom<(Self, Option<&api_models::payments::AdditionalPaymentData>)>
for Option<enums::PaymentMethodType>
{
fn foreign_from(req: (Self, Option<&api_models::payments::AdditionalPaymentData>)) -> Self {
let (payment_method_type, additional_pm_data) = req;
additional_pm_data
.and_then(|pm_data| {
if let api_models::payments::AdditionalPaymentData::Card(card_info) = pm_data {
card_info.card_type.as_ref().and_then(|card_type_str| {
api_models::enums::PaymentMethodType::from_str(&card_type_str.to_lowercase()).map_err(|err| {
crate::logger::error!(
"Err - {:?}\nInvalid card_type value found in BIN DB - {:?}",
err,
card_type_str,
);
}).ok()
})
} else {
None
}
})
.map_or(payment_method_type, |card_type_in_bin_store| {
if let Some(card_type_in_req) = payment_method_type {
if card_type_in_req != card_type_in_bin_store {
crate::logger::info!(
"Mismatch in card_type\nAPI request - {}; BIN lookup - {}\nOverriding with {}",
card_type_in_req, card_type_in_bin_store, card_type_in_bin_store,
);
}
}
Some(card_type_in_bin_store)
})
}
}

0 comments on commit 6230eb4

Please # to comment.