Skip to content

Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation

fix(core): `payment_method_type` not set in the payment attempt when making a recurring mandate payment (#1415)

Pa1NarK38b9e59b7511
diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rs
index 2795ad251b..980a4e6566 100644
--- a/crates/router/src/core/payments/helpers.rs
+++ b/crates/router/src/core/payments/helpers.rs
@@ -272,6 +272,7 @@ pub async fn get_token_pm_type_mandate_details(
) -> RouterResult<(
Option<String>,
Option<storage_enums::PaymentMethod>,
+ Option<storage_enums::PaymentMethodType>,
Option<api::MandateData>,
Option<String>,
)> {
@@ -284,18 +285,27 @@ pub async fn get_token_pm_type_mandate_details(
Ok((
request.payment_token.to_owned(),
request.payment_method.map(ForeignInto::foreign_into),
+ request.payment_method_type.map(ForeignInto::foreign_into),
Some(setup_mandate),
None,
))
}
Some(api::MandateTxnType::RecurringMandateTxn) => {
- let (token_, payment_method_type_, mandate_connector) =
+ let (token_, payment_method_, payment_method_type_, mandate_connector) =
get_token_for_recurring_mandate(state, request, merchant_account).await?;
- Ok((token_, payment_method_type_, None, mandate_connector))
+ Ok((
+ token_,
+ payment_method_,
+ payment_method_type_
+ .or_else(|| request.payment_method_type.map(ForeignInto::foreign_into)),
+ None,
+ mandate_connector,
+ ))
}
None => Ok((
request.payment_token.to_owned(),
request.payment_method.map(ForeignInto::foreign_into),
+ request.payment_method_type.map(ForeignInto::foreign_into),
request.mandate_data.clone(),
None,
)),
@@ -309,6 +319,7 @@ pub async fn get_token_for_recurring_mandate(
) -> RouterResult<(
Option<String>,
Option<storage_enums::PaymentMethod>,
+ Option<storage_enums::PaymentMethodType>,
Option<String>,
)> {
let db = &*state.store;
@@ -368,12 +379,14 @@ pub async fn get_token_for_recurring_mandate(
Ok((
Some(token),
Some(payment_method.payment_method),
+ payment_method.payment_method_type,
Some(mandate.connector),
))
} else {
Ok((
None,
Some(payment_method.payment_method),
+ payment_method.payment_method_type,
Some(mandate.connector),
))
}
diff --git a/crates/router/src/core/payments/operations/payment_complete_authorize.rs b/crates/router/src/core/payments/operations/payment_complete_authorize.rs
index 4618076a16..8a1dc78008 100644
--- a/crates/router/src/core/payments/operations/payment_complete_authorize.rs
+++ b/crates/router/src/core/payments/operations/payment_complete_authorize.rs
@@ -70,7 +70,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Co
"confirm",
)?;
- let (token, payment_method, setup_mandate, mandate_connector) =
+ let (token, payment_method, payment_method_type, setup_mandate, mandate_connector) =
helpers::get_token_pm_type_mandate_details(
state,
request,
@@ -110,10 +110,8 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Co
payment_attempt.payment_method = payment_method.or(payment_attempt.payment_method);
payment_attempt.browser_info = browser_info;
- payment_attempt.payment_method_type = request
- .payment_method_type
- .map(|pmt| pmt.foreign_into())
- .or(payment_attempt.payment_method_type);
+ payment_attempt.payment_method_type =
+ payment_method_type.or(payment_attempt.payment_method_type);
payment_attempt.payment_experience = request
.payment_experience
.map(|experience| experience.foreign_into());
diff --git a/crates/router/src/core/payments/operations/payment_confirm.rs b/crates/router/src/core/payments/operations/payment_confirm.rs
index 8e6eb78f35..513edfaf1f 100644
--- a/crates/router/src/core/payments/operations/payment_confirm.rs
+++ b/crates/router/src/core/payments/operations/payment_confirm.rs
@@ -103,7 +103,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Pa
.map(ForeignInto::foreign_into)
.or(payment_intent.setup_future_usage);
- let (token, payment_method, setup_mandate, mandate_connector) =
+ let (token, payment_method, payment_method_type, setup_mandate, mandate_connector) =
helpers::get_token_pm_type_mandate_details(
state,
request,
@@ -138,10 +138,8 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Pa
payment_attempt.payment_method = payment_method.or(payment_attempt.payment_method);
payment_attempt.browser_info = browser_info;
- payment_attempt.payment_method_type = request
- .payment_method_type
- .map(|pmt| pmt.foreign_into())
- .or(payment_attempt.payment_method_type);
+ payment_attempt.payment_method_type =
+ payment_method_type.or(payment_attempt.payment_method_type);
payment_attempt.payment_experience = request
.payment_experience
diff --git a/crates/router/src/core/payments/operations/payment_create.rs b/crates/router/src/core/payments/operations/payment_create.rs
index 44f7c0a863..e68eb0c485 100644
--- a/crates/router/src/core/payments/operations/payment_create.rs
+++ b/crates/router/src/core/payments/operations/payment_create.rs
@@ -65,7 +65,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Pa
.get_payment_intent_id()
.change_context(errors::ApiErrorResponse::PaymentNotFound)?;
- let (token, payment_method_type, setup_mandate, mandate_connector) =
+ let (token, payment_method, payment_method_type, setup_mandate, mandate_connector) =
helpers::get_token_pm_type_mandate_details(
state,
request,
@@ -111,6 +111,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Pa
&payment_id,
merchant_id,
money,
+ payment_method,
payment_method_type,
request,
browser_info,
@@ -493,6 +494,7 @@ impl PaymentCreate {
merchant_id: &str,
money: (api::Amount, enums::Currency),
payment_method: Option<enums::PaymentMethod>,
+ payment_method_type: Option<enums::PaymentMethodType>,
request: &api::PaymentsRequest,
browser_info: Option<serde_json::Value>,
) -> RouterResult<storage::PaymentAttemptNew> {
@@ -528,7 +530,7 @@ impl PaymentCreate {
authentication_type: request.authentication_type.map(ForeignInto::foreign_into),
browser_info,
payment_experience: request.payment_experience.map(ForeignInto::foreign_into),
- payment_method_type: request.payment_method_type.map(ForeignInto::foreign_into),
+ payment_method_type,
payment_method_data: additional_pm_data,
amount_to_capture: request.amount_to_capture,
payment_token: request.payment_token.clone(),
diff --git a/crates/router/src/core/payments/operations/payment_update.rs b/crates/router/src/core/payments/operations/payment_update.rs
index 1d7f6cce49..4765e6a7e3 100644
--- a/crates/router/src/core/payments/operations/payment_update.rs
+++ b/crates/router/src/core/payments/operations/payment_update.rs
@@ -75,7 +75,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Pa
"update",
)?;
- let (token, payment_method_type, setup_mandate, mandate_connector) =
+ let (token, payment_method, payment_method_type, setup_mandate, mandate_connector) =
helpers::get_token_pm_type_mandate_details(
state,
request,
@@ -108,7 +108,9 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Pa
None => payment_attempt.currency.get_required_value("currency")?,
};
- payment_attempt.payment_method = payment_method_type.or(payment_attempt.payment_method);
+ payment_attempt.payment_method = payment_method.or(payment_attempt.payment_method);
+ payment_attempt.payment_method_type =
+ payment_method_type.or(payment_attempt.payment_method_type);
let customer_details = helpers::get_customer_details_from_request(request);
let amount = request