Skip to content

Commit 52abda9

Browse files
fix(router): override setup_future_usage filed to on_session based on merchant config (#5195)
1 parent bf9893e commit 52abda9

File tree

6 files changed

+38
-22
lines changed

6 files changed

+38
-22
lines changed

crates/router/src/core/payments.rs

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3279,7 +3279,7 @@ where
32793279
&& should_do_retry
32803280
{
32813281
let retryable_connector_data = helpers::get_apple_pay_retryable_connectors(
3282-
state,
3282+
&state,
32833283
merchant_account,
32843284
payment_data,
32853285
key_store,
@@ -3303,6 +3303,8 @@ where
33033303
.first()
33043304
.ok_or(errors::ApiErrorResponse::IncorrectPaymentMethodConfiguration)?;
33053305

3306+
helpers::override_setup_future_usage_to_on_session(&*state.store, payment_data).await?;
3307+
33063308
return Ok(ConnectorCallType::PreDetermined(
33073309
first_pre_routing_connector_data_list.clone(),
33083310
));
@@ -3598,24 +3600,7 @@ pub async fn decide_multiplex_connector_for_normal_or_recurring_payment<F: Clone
35983600
Ok(ConnectorCallType::PreDetermined(chosen_connector_data))
35993601
}
36003602
_ => {
3601-
let skip_saving_wallet_at_connector_optional =
3602-
helpers::config_skip_saving_wallet_at_connector(
3603-
&*state.store,
3604-
&payment_data.payment_intent.merchant_id,
3605-
)
3606-
.await?;
3607-
3608-
if let Some(skip_saving_wallet_at_connector) = skip_saving_wallet_at_connector_optional
3609-
{
3610-
if let Some(payment_method_type) = payment_data.payment_attempt.payment_method_type
3611-
{
3612-
if skip_saving_wallet_at_connector.contains(&payment_method_type) {
3613-
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.");
3614-
payment_data.payment_intent.setup_future_usage =
3615-
Some(enums::FutureUsage::OnSession);
3616-
}
3617-
}
3618-
};
3603+
helpers::override_setup_future_usage_to_on_session(&*state.store, payment_data).await?;
36193604

36203605
let first_choice = connectors
36213606
.first()

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

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,7 @@ pub async fn get_token_pm_type_mandate_details(
451451
merchant_account: &domain::MerchantAccount,
452452
merchant_key_store: &domain::MerchantKeyStore,
453453
payment_method_id: Option<String>,
454+
customer_id: &Option<id_type::CustomerId>,
454455
) -> RouterResult<MandateGenericData> {
455456
let mandate_data = request.mandate_data.clone().map(MandateData::foreign_from);
456457
let (
@@ -554,7 +555,9 @@ pub async fn get_token_pm_type_mandate_details(
554555
|| request.payment_method_type
555556
== Some(api_models::enums::PaymentMethodType::GooglePay)
556557
{
557-
if let Some(customer_id) = &request.customer_id {
558+
if let Some(customer_id) =
559+
&request.customer_id.clone().or(customer_id.clone())
560+
{
558561
let customer_saved_pm_option = match state
559562
.store
560563
.find_payment_method_by_customer_id_merchant_id_list(
@@ -4158,7 +4161,7 @@ pub fn get_applepay_metadata(
41584161

41594162
#[cfg(all(feature = "retry", feature = "connector_choice_mca_id"))]
41604163
pub async fn get_apple_pay_retryable_connectors<F>(
4161-
state: SessionState,
4164+
state: &SessionState,
41624165
merchant_account: &domain::MerchantAccount,
41634166
payment_data: &mut PaymentData<F>,
41644167
key_store: &domain::MerchantKeyStore,
@@ -4182,7 +4185,7 @@ where
41824185
.ok_or(errors::ApiErrorResponse::IncorrectPaymentMethodConfiguration)?;
41834186

41844187
let merchant_connector_account_type = get_merchant_connector_account(
4185-
&state,
4188+
state,
41864189
merchant_account.merchant_id.as_str(),
41874190
payment_data.creds_identifier.to_owned(),
41884191
key_store,
@@ -4999,3 +5002,25 @@ pub async fn config_skip_saving_wallet_at_connector(
49995002
}
50005003
})
50015004
}
5005+
5006+
pub async fn override_setup_future_usage_to_on_session<F: Clone>(
5007+
db: &dyn StorageInterface,
5008+
payment_data: &mut PaymentData<F>,
5009+
) -> CustomResult<(), errors::ApiErrorResponse> {
5010+
if payment_data.payment_intent.setup_future_usage == Some(enums::FutureUsage::OffSession) {
5011+
let skip_saving_wallet_at_connector_optional =
5012+
config_skip_saving_wallet_at_connector(db, &payment_data.payment_intent.merchant_id)
5013+
.await?;
5014+
5015+
if let Some(skip_saving_wallet_at_connector) = skip_saving_wallet_at_connector_optional {
5016+
if let Some(payment_method_type) = payment_data.payment_attempt.payment_method_type {
5017+
if skip_saving_wallet_at_connector.contains(&payment_method_type) {
5018+
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.");
5019+
payment_data.payment_intent.setup_future_usage =
5020+
Some(enums::FutureUsage::OnSession);
5021+
}
5022+
}
5023+
};
5024+
};
5025+
Ok(())
5026+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Co
124124
merchant_account,
125125
key_store,
126126
payment_attempt.payment_method_id.clone(),
127+
&payment_intent.customer_id,
127128
)
128129
.await?;
129130
let token = token.or_else(|| payment_attempt.payment_token.clone());

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,8 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Pa
495495
let m_request = request.clone();
496496
let m_key_store = key_store.clone();
497497

498+
let payment_intent_customer_id = payment_intent.customer_id.clone();
499+
498500
let mandate_details_fut = tokio::spawn(
499501
async move {
500502
helpers::get_token_pm_type_mandate_details(
@@ -504,6 +506,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Pa
504506
&m_merchant_account,
505507
&m_key_store,
506508
None,
509+
&payment_intent_customer_id,
507510
)
508511
.await
509512
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Pa
136136
merchant_account,
137137
merchant_key_store,
138138
None,
139+
&request.customer_id,
139140
)
140141
.await?;
141142

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Pa
148148
merchant_account,
149149
key_store,
150150
None,
151+
&payment_intent.customer_id,
151152
)
152153
.await?;
153154
helpers::validate_amount_to_capture_and_capture_method(Some(&payment_attempt), request)?;

0 commit comments

Comments
 (0)