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(router): `override setup_future_usage` filed to on_session based on merchant config (#5195)

Shankar Singh C52abda9bd17c
diff --git a/crates/router/src/core/payments.rs b/crates/router/src/core/payments.rs
index f65cc052ea..4af5a2ed30 100644
--- a/crates/router/src/core/payments.rs
+++ b/crates/router/src/core/payments.rs
@@ -3279,7 +3279,7 @@ where
&& should_do_retry
{
let retryable_connector_data = helpers::get_apple_pay_retryable_connectors(
- state,
+ &state,
merchant_account,
payment_data,
key_store,
@@ -3303,6 +3303,8 @@ where
.first()
.ok_or(errors::ApiErrorResponse::IncorrectPaymentMethodConfiguration)?;
+ helpers::override_setup_future_usage_to_on_session(&*state.store, payment_data).await?;
+
return Ok(ConnectorCallType::PreDetermined(
first_pre_routing_connector_data_list.clone(),
));
@@ -3598,24 +3600,7 @@ pub async fn decide_multiplex_connector_for_normal_or_recurring_payment<F: Clone
Ok(ConnectorCallType::PreDetermined(chosen_connector_data))
}
_ => {
- let skip_saving_wallet_at_connector_optional =
- helpers::config_skip_saving_wallet_at_connector(
- &*state.store,
- &payment_data.payment_intent.merchant_id,
- )
- .await?;
-
- if let Some(skip_saving_wallet_at_connector) = skip_saving_wallet_at_connector_optional
- {
- if let Some(payment_method_type) = payment_data.payment_attempt.payment_method_type
- {
- if skip_saving_wallet_at_connector.contains(&payment_method_type) {
- logger::debug!("Override setup_future_usage from off_session to on_session based on the merchant's skip_saving_wallet_at_connector configuration to avoid creating a connector mandate.");
- payment_data.payment_intent.setup_future_usage =
- Some(enums::FutureUsage::OnSession);
- }
- }
- };
+ helpers::override_setup_future_usage_to_on_session(&*state.store, payment_data).await?;
let first_choice = connectors
.first()
diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rs
index 534da72a1d..e59e5e6dd8 100644
--- a/crates/router/src/core/payments/helpers.rs
+++ b/crates/router/src/core/payments/helpers.rs
@@ -451,6 +451,7 @@ pub async fn get_token_pm_type_mandate_details(
merchant_account: &domain::MerchantAccount,
merchant_key_store: &domain::MerchantKeyStore,
payment_method_id: Option<String>,
+ customer_id: &Option<id_type::CustomerId>,
) -> RouterResult<MandateGenericData> {
let mandate_data = request.mandate_data.clone().map(MandateData::foreign_from);
let (
@@ -554,7 +555,9 @@ pub async fn get_token_pm_type_mandate_details(
|| request.payment_method_type
== Some(api_models::enums::PaymentMethodType::GooglePay)
{
- if let Some(customer_id) = &request.customer_id {
+ if let Some(customer_id) =
+ &request.customer_id.clone().or(customer_id.clone())
+ {
let customer_saved_pm_option = match state
.store
.find_payment_method_by_customer_id_merchant_id_list(
@@ -4158,7 +4161,7 @@ pub fn get_applepay_metadata(
#[cfg(all(feature = "retry", feature = "connector_choice_mca_id"))]
pub async fn get_apple_pay_retryable_connectors<F>(
- state: SessionState,
+ state: &SessionState,
merchant_account: &domain::MerchantAccount,
payment_data: &mut PaymentData<F>,
key_store: &domain::MerchantKeyStore,
@@ -4182,7 +4185,7 @@ where
.ok_or(errors::ApiErrorResponse::IncorrectPaymentMethodConfiguration)?;
let merchant_connector_account_type = get_merchant_connector_account(
- &state,
+ state,
merchant_account.merchant_id.as_str(),
payment_data.creds_identifier.to_owned(),
key_store,
@@ -4999,3 +5002,25 @@ pub async fn config_skip_saving_wallet_at_connector(
}
})
}
+
+pub async fn override_setup_future_usage_to_on_session<F: Clone>(
+ db: &dyn StorageInterface,
+ payment_data: &mut PaymentData<F>,
+) -> CustomResult<(), errors::ApiErrorResponse> {
+ if payment_data.payment_intent.setup_future_usage == Some(enums::FutureUsage::OffSession) {
+ let skip_saving_wallet_at_connector_optional =
+ config_skip_saving_wallet_at_connector(db, &payment_data.payment_intent.merchant_id)
+ .await?;
+
+ if let Some(skip_saving_wallet_at_connector) = skip_saving_wallet_at_connector_optional {
+ if let Some(payment_method_type) = payment_data.payment_attempt.payment_method_type {
+ if skip_saving_wallet_at_connector.contains(&payment_method_type) {
+ logger::debug!("Override setup_future_usage from off_session to on_session based on the merchant's skip_saving_wallet_at_connector configuration to avoid creating a connector mandate.");
+ payment_data.payment_intent.setup_future_usage =
+ Some(enums::FutureUsage::OnSession);
+ }
+ }
+ };
+ };
+ Ok(())
+}
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 4fd427e38f..7188a8216d 100644
--- a/crates/router/src/core/payments/operations/payment_complete_authorize.rs
+++ b/crates/router/src/core/payments/operations/payment_complete_authorize.rs
@@ -124,6 +124,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Co
merchant_account,
key_store,
payment_attempt.payment_method_id.clone(),
+ &payment_intent.customer_id,
)
.await?;
let token = token.or_else(|| payment_attempt.payment_token.clone());
diff --git a/crates/router/src/core/payments/operations/payment_confirm.rs b/crates/router/src/core/payments/operations/payment_confirm.rs
index 5e35b918a0..99ac4e3e97 100644
--- a/crates/router/src/core/payments/operations/payment_confirm.rs
+++ b/crates/router/src/core/payments/operations/payment_confirm.rs
@@ -495,6 +495,8 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Pa
let m_request = request.clone();
let m_key_store = key_store.clone();
+ let payment_intent_customer_id = payment_intent.customer_id.clone();
+
let mandate_details_fut = tokio::spawn(
async move {
helpers::get_token_pm_type_mandate_details(
@@ -504,6 +506,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Pa
&m_merchant_account,
&m_key_store,
None,
+ &payment_intent_customer_id,
)
.await
}
diff --git a/crates/router/src/core/payments/operations/payment_create.rs b/crates/router/src/core/payments/operations/payment_create.rs
index b8045487d9..fc1f53d358 100644
--- a/crates/router/src/core/payments/operations/payment_create.rs
+++ b/crates/router/src/core/payments/operations/payment_create.rs
@@ -136,6 +136,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Pa
merchant_account,
merchant_key_store,
None,
+ &request.customer_id,
)
.await?;
diff --git a/crates/router/src/core/payments/operations/payment_update.rs b/crates/router/src/core/payments/operations/payment_update.rs
index c34a40fd90..c9b778fae3 100644
--- a/crates/router/src/core/payments/operations/payment_update.rs
+++ b/crates/router/src/core/payments/operations/payment_update.rs
@@ -148,6 +148,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Pa
merchant_account,
key_store,
None,
+ &payment_intent.customer_id,
)
.await?;
helpers::validate_amount_to_capture_and_capture_method(Some(&payment_attempt), request)?;