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
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
fix(router): add setup future usage check in payment session tokens flow to fetch vault session details (#13590)
Prasunna Soppac7009fd34ec2
diff --git a/crates/router/src/core/payment_methods.rs b/crates/router/src/core/payment_methods.rsindex 85fc4b266b..d511f90074 100644--- a/crates/router/src/core/payment_methods.rs+++ b/crates/router/src/core/payment_methods.rs@@ -7307,7 +7307,15 @@ pub async fn payment_methods_session_confirm(}).or_else(|| payment_method_session_billing.clone());- let storage_type = payment_method_session.storage_type;+ // The session's storage_type carries the merchant's intent (persistent when+ // setup_future_usage and a customer are present at session create). The customer's+ // acceptance at confirm makes the save final: without it the payment method is+ // created as volatile even when the session asked for persistent storage.+ let storage_type = if request.customer_acceptance.is_some() {+ payment_method_session.storage_type+ } else {+ common_enums::StorageType::Volatile+ };let create_payment_method_request = get_payment_method_create_request(requestdiff --git a/crates/router/src/core/payments/vault_session.rs b/crates/router/src/core/payments/vault_session.rsindex 76a982f674..e057fb3b48 100644--- a/crates/router/src/core/payments/vault_session.rs+++ b/crates/router/src/core/payments/vault_session.rs@@ -115,6 +115,7 @@ async fn call_internal_pm_session_create_for_vault(state: &SessionState,profile: &domain::Profile,customer_id: Option<&id_type::CustomerId>,+ storage_type: common_enums::StorageType,) -> RouterResult<Option<api::VaultDetails>> {use common_utils::request::Headers;use payment_methods::client::{@@ -150,14 +151,6 @@ async fn call_internal_pm_session_create_for_vault(&state.conf.trace_header.header_name,);- // Guest flow (no customer) uses volatile storage; a known customer uses persistent. This is- // forwarded to the modular PM service, which in turn drives the external vault session create.- let storage_type = if customer_id.is_some() {- common_enums::StorageType::Persistent- } else {- common_enums::StorageType::Volatile- };-let request = CreatePaymentMethodSessionV1Request {customer_id: customer_id.cloned(),modular_service_prefix: state.conf.micro_services.payment_methods_prefix.0.clone(),@@ -226,19 +219,36 @@ wherehelpers::resolve_provider_profile(state, platform, profile).await?;let customer_id = customer.as_ref().map(|c| c.get_id());+ // `setup_future_usage` on the intent carries the merchant's storage intent for the+ // session: set (on_session/off_session) → persistent, absent → volatile. Persistent+ // intent without a customer_id is rejected at payment create/confirm+ // (`validate_customer_id_mandatory_cases`), so a persistent session always has a+ // customer to attach to.+ let storage_type = match (+ payment_data.get_payment_intent().setup_future_usage,+ customer_id,+ ) {+ (Some(_), Some(_)) => common_enums::StorageType::Persistent,+ _ => common_enums::StorageType::Volatile,+ };+// Use the resolved external vault profile (the platform merchant's profile in platform// flows) so the PM service operates under the merchant that actually holds the external// vault configuration. For standard merchants this is the payment profile itself.- let vault_details =- call_internal_pm_session_create_for_vault(state, &external_vault_profile, customer_id)- .await- .unwrap_or_else(|err| {- router_env::logger::warn!(- ?err,- "Failed to fetch vault details via internal PM session service"- );- None- });+ let vault_details = call_internal_pm_session_create_for_vault(+ state,+ &external_vault_profile,+ customer_id,+ storage_type,+ )+ .await+ .unwrap_or_else(|err| {+ router_env::logger::warn!(+ ?err,+ "Failed to fetch vault details via internal PM session service"+ );+ None+ });payment_data.set_vault_session_details(vault_details);}