fix(router): override setup_future_usage filed to on_session based on merchant config (#5195)

This commit is contained in:
Shankar Singh C
2024-07-04 15:57:27 +05:30
committed by GitHub
parent bf9893e230
commit 52abda9bd1
6 changed files with 38 additions and 22 deletions

View File

@ -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()

View File

@ -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(())
}

View File

@ -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());

View File

@ -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
}

View File

@ -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?;

View File

@ -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)?;