Skip to content

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

feat(account_updater): sync stored card before merchant-initiated payments (#13786)

Kanika Bansald38557673a50
diff --git a/crates/payment_methods/src/client/retrieve.rs b/crates/payment_methods/src/client/retrieve.rs
index cf87f95af0..5bd1567a35 100644
--- a/crates/payment_methods/src/client/retrieve.rs
+++ b/crates/payment_methods/src/client/retrieve.rs
@@ -19,6 +19,7 @@ pub struct RetrievePaymentMethodV1Request {
pub payment_method_id: PaymentMethodId,
pub modular_service_prefix: String,
pub fetch_raw_detail: bool,
+ pub force_sync: bool,
}
/// V1-facing retrieve response payload.
#[derive(Clone, Debug)]
@@ -113,7 +114,10 @@ impl RetrievePaymentMethod {
&self,
request: &RetrievePaymentMethodV1Request,
) -> Vec<(&'static str, String)> {
- vec![("fetch_raw_detail", request.fetch_raw_detail.to_string())]
+ vec![
+ ("fetch_raw_detail", request.fetch_raw_detail.to_string()),
+ ("force_sync", request.force_sync.to_string()),
+ ]
}
}
diff --git a/crates/router/src/core/payment_methods/transformers.rs b/crates/router/src/core/payment_methods/transformers.rs
index e411ec5eaa..c2552a3c77 100644
--- a/crates/router/src/core/payment_methods/transformers.rs
+++ b/crates/router/src/core/payment_methods/transformers.rs
@@ -1989,12 +1989,15 @@ pub async fn fetch_payment_method_from_modular_service(
// the internal vault, so requesting raw detail yields an "Invalid Vault Response" error; the
// external vault token reference is returned regardless. The normal confirm flow uses `true`.
fetch_raw_detail: bool,
+ // Whether to have the modular service sync the stored card with the Account Updater first.
+ force_sync: bool,
) -> CustomResult<PaymentMethodWithRawData, errors::ApiErrorResponse> {
let payment_method_fetch_req = RetrievePaymentMethodV1Request {
payment_method_id: api_models::payment_methods::PaymentMethodId {
payment_method_id: payment_method_id.to_owned(),
},
fetch_raw_detail,
+ force_sync,
modular_service_prefix: state.conf.micro_services.payment_methods_prefix.0.clone(),
};
diff --git a/crates/router/src/core/payments.rs b/crates/router/src/core/payments.rs
index d4104cb32c..206cb611cb 100644
--- a/crates/router/src/core/payments.rs
+++ b/crates/router/src/core/payments.rs
@@ -10272,8 +10272,9 @@ impl PaymentEligibilityData {
platform,
profile_id,
payment_method_id.as_str(),
- None, // CVC is not collected during the eligibility check
- true, // fetch raw card detail from the internal vault
+ None, // CVC is not collected during the eligibility check
+ true, // fetch raw card detail from the internal vault
+ false, // an eligibility check is not a payment
)
.await
.change_context(errors::ApiErrorResponse::PaymentMethodNotFound)
@@ -10319,8 +10320,9 @@ impl PaymentEligibilityData {
platform,
profile_id,
payment_method.get_id(),
- None, // CVC is not collected during the eligibility check
- true, // fetch raw card detail from the internal vault
+ None, // CVC is not collected during the eligibility check
+ true, // fetch raw card detail from the internal vault
+ false, // an eligibility check is not a payment
)
.await
.change_context(errors::ApiErrorResponse::PaymentMethodNotFound)
diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rs
index 68a6340890..31fa183b96 100644
--- a/crates/router/src/core/payments/helpers.rs
+++ b/crates/router/src/core/payments/helpers.rs
@@ -9837,6 +9837,25 @@ pub async fn get_merchant_connector_account_v2(
}
}
+#[cfg(feature = "v1")]
+pub fn is_off_session_mit_for_payment_method(
+ req: &api::PaymentsRequest,
+ payment_method_id: &str,
+) -> bool {
+ req.confirm == Some(true)
+ && req.off_session == Some(true)
+ && req
+ .recurring_details
+ .as_ref()
+ .is_some_and(|recurring_details| {
+ matches!(
+ recurring_details,
+ RecurringDetails::PaymentMethodId(recurring_payment_method_id)
+ if recurring_payment_method_id.as_str() == payment_method_id
+ )
+ })
+}
+
pub fn is_stored_credential(
recurring_details: &Option<RecurringDetails>,
payment_token: &Option<String>,
diff --git a/crates/router/src/core/payments/operations/payment_confirm.rs b/crates/router/src/core/payments/operations/payment_confirm.rs
index 44fab4b692..ad22977757 100644
--- a/crates/router/src/core/payments/operations/payment_confirm.rs
+++ b/crates/router/src/core/payments/operations/payment_confirm.rs
@@ -2549,6 +2549,7 @@ impl PaymentConfirm {
payment_method_ref,
card_token_data,
true, // fetch raw card detail from the internal vault
+ helpers::is_off_session_mit_for_payment_method(req, payment_method_ref),
)
.await?;
logger::info!("Payment method fetched from PM Modular Service.");
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.rs
index 47a96e9714..0a3f5c5e9e 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
@@ -769,6 +769,8 @@ impl<F: Clone + Send + Sync> Domain<F, PaymentsRequest, PaymentData<F>>
// External vault proxy cards are not in the internal vault; requesting raw
// detail fails. The external vault token reference is returned without it.
false,
+ // Account Updater does not cover external vault cards.
+ false,
)
.await
.attach_printable(
@@ -822,6 +824,7 @@ impl<F: Clone + Send + Sync> Domain<F, PaymentsRequest, PaymentData<F>>
&existing_pm_id,
None,
false,
+ false,
)
.await
{
diff --git a/crates/router/src/core/payments/operations/payment_create.rs b/crates/router/src/core/payments/operations/payment_create.rs
index d132ef1c9c..0296a126a3 100644
--- a/crates/router/src/core/payments/operations/payment_create.rs
+++ b/crates/router/src/core/payments/operations/payment_create.rs
@@ -1372,6 +1372,7 @@ impl PaymentCreate {
payment_method_ref,
None, // CVC token data is not passed in create api
true, // fetch raw card detail from the internal vault
+ helpers::is_off_session_mit_for_payment_method(req, payment_method_ref),
)
.await?;
logger::info!("Payment method fetched from PM Modular Service.");