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(external_vault): reuse saved PM on repeat & populate /client card scheme (#12882)
Shankar Singh C1e381c168785
diff --git a/crates/payment_methods/src/types.rs b/crates/payment_methods/src/types.rsindex b49cb0e993..e5d79955a1 100644--- a/crates/payment_methods/src/types.rs+++ b/crates/payment_methods/src/types.rs@@ -201,9 +201,22 @@ impl From<PaymentMethodResponseData>{fn from(payment_method_response_data: PaymentMethodResponseData) -> Self {match payment_method_response_data {- PaymentMethodResponseData::Card(card_info) => Some(- api_models::payment_methods::CustomerPaymentMethodDataForClient::Card(card_info),- ),+ PaymentMethodResponseData::Card(mut card_info) => {+ // The modular PM service returns `scheme` as null on the card detail even though+ // `card_network` is populated. Surface the network as the scheme (mirroring+ // `mk_add_card_response_hs`) so the `/client` response carries it.+ card_info.scheme = card_info.scheme.or_else(|| {+ card_info+ .card_network+ .as_ref()+ .map(|network| network.to_string())+ });+ Some(+ api_models::payment_methods::CustomerPaymentMethodDataForClient::Card(+ card_info,+ ),+ )+ }PaymentMethodResponseData::Wallet(wallet_info) => Some(api_models::payment_methods::CustomerPaymentMethodDataForClient::Wallet(wallet_info.into(),diff --git a/crates/router/src/core/payments/operations/payment_confirm_external_vault_proxy.rs b/crates/router/src/core/payments/operations/payment_confirm_external_vault_proxy.rsindex cee92f3714..28ec7dcaea 100644--- a/crates/router/src/core/payments/operations/payment_confirm_external_vault_proxy.rs+++ b/crates/router/src/core/payments/operations/payment_confirm_external_vault_proxy.rs@@ -642,6 +642,23 @@ impl<F: Clone + Send + Sync> Domain<F, PaymentsRequest, PaymentData<F>>router_env::logger::info!("Skipping PM creation: customer_acceptance is None");return Ok(());}+ // A repeat payment that reuses a saved card (the `VaultCardTokenData` / `payment_token`+ // flow) already had its existing payment method resolved into `payment_method_info` during+ // `get_trackers`. Creating again here would insert a duplicate `payment_methods` record for+ // the same card on every off-session repeat, so reuse the existing one — just record its id+ // on the attempt. The PM was fetched from the modular service (already `version: V2`), so the+ // post-payment update still takes the modular acknowledgement path, not the legacy save path.+ if let Some(existing_pm_id) = payment_data+ .payment_method_info+ .as_ref()+ .map(|existing_pm| existing_pm.get_id().clone())+ {+ router_env::logger::info!(+ "Reusing existing payment method resolved from payment_token; skipping duplicate PM creation"+ );+ payment_data.set_payment_method_id_in_attempt(Some(existing_pm_id));+ return Ok(());+ }// Only create for ExternalVaultCard (proxy card flow)let mut vault_card = match payment_data.external_vault_pmd.clone() {Some(diff --git a/cypress-tests/cypress/support/redirectionHandler.js b/cypress-tests/cypress/support/redirectionHandler.jsindex 206d186f95..0b180537d0 100644--- a/cypress-tests/cypress/support/redirectionHandler.js+++ b/cypress-tests/cypress/support/redirectionHandler.js@@ -283,19 +283,21 @@ function cryptoRedirection(// Email (optional, but fill it)cy.get('input[type="email"]').then(($el) => {if ($el.length > 0) {- cy.wrap($el.first())- .clear()- .type(coingateBilling.email);+ cy.wrap($el.first()).clear().type(coingateBilling.email);}});// First name + Last name (inputs with latin-characters placeholder)cy.get('input[placeholder*="latin"]').then(($inputs) => {if ($inputs.length >= 1) {- cy.wrap($inputs.eq(0)).clear().type(coingateBilling.firstName);+ cy.wrap($inputs.eq(0))+ .clear()+ .type(coingateBilling.firstName);}if ($inputs.length >= 2) {- cy.wrap($inputs.eq(1)).clear().type(coingateBilling.lastName);+ cy.wrap($inputs.eq(1))+ .clear()+ .type(coingateBilling.lastName);}});