Skip to content

Commit

Permalink
fix(router): override setup_future_usage filed to on_session based …
Browse files Browse the repository at this point in the history
…on merchant config (#5195)
  • Loading branch information
ShankarSinghC authored Jul 4, 2024
1 parent bf9893e commit 52abda9
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 22 deletions.
23 changes: 4 additions & 19 deletions crates/router/src/core/payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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(),
));
Expand Down Expand Up @@ -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()
Expand Down
31 changes: 28 additions & 3 deletions crates/router/src/core/payments/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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(())
}
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
3 changes: 3 additions & 0 deletions crates/router/src/core/payments/operations/payment_confirm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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?;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand Down

0 comments on commit 52abda9

Please sign in to comment.