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

fix(modular): forward compatibility job (#12895)

Kashiff75fb607c254
diff --git a/crates/router/src/core/payment_methods/cards.rs b/crates/router/src/core/payment_methods/cards.rs
index 616a32ce77..44cc927883 100644
--- a/crates/router/src/core/payment_methods/cards.rs
+++ b/crates/router/src/core/payment_methods/cards.rs
@@ -855,6 +855,7 @@ impl PaymentMethodsController for PmCards<'_> {
customer_id,
pmd,
self.state.conf.locker.ttl_for_storage_in_secs,
+ None,
)?;
let query_params = Some(pm_types::VaultQueryParam::from(pm_types::WriteMode::Insert));
@@ -960,6 +961,7 @@ impl PaymentMethodsController for PmCards<'_> {
customer_id,
pmd,
self.state.conf.locker.ttl_for_storage_in_secs,
+ None,
)?;
let query_params = Some(pm_types::VaultQueryParam::from(pm_types::WriteMode::Insert));
@@ -1870,18 +1872,33 @@ pub fn encode_add_vault_request(
customer_id: &id_type::CustomerId,
pmd: hyperswitch_domain_models::vault::PaymentMethodVaultingData,
ttl: i64,
+ vault_id: Option<domain::VaultId>,
) -> errors::CustomResult<Vec<u8>, errors::VaultError> {
if should_trigger_fingerprint_migration {
+ // New fingerprint migration path uses merchant-scoped vault entity ids.
pm_types::AddVaultRequestNew {
entity_id: merchant_id,
- vault_id: domain::VaultId::generate(uuid::Uuid::now_v7().to_string()),
+ vault_id: vault_id
+ .unwrap_or_else(|| domain::VaultId::generate(uuid::Uuid::now_v7().to_string())),
data: pmd,
ttl,
}
.encode_to_vec()
.change_context(errors::VaultError::RequestEncodingFailed)
.attach_printable("Failed to encode AddVaultRequestNew")
+ } else if let Some(vault_id) = vault_id {
+ // Forward-compat PT reuses the existing locker id so modular reads can address the row.
+ pm_types::AddCompatVaultRequest {
+ entity_id: customer_id.to_owned(),
+ vault_id,
+ data: pmd,
+ ttl,
+ }
+ .encode_to_vec()
+ .change_context(errors::VaultError::RequestEncodingFailed)
+ .attach_printable("Failed to encode AddCompatVaultRequest")
} else {
+ // Legacy v1 add path keeps the original merchant-and-customer entity id shape.
pm_types::AddVaultRequest {
entity_id: hyperswitch_domain_models::vault::V1VaultEntityId::new(
merchant_id,
@@ -1944,11 +1961,15 @@ pub fn encode_add_vault_request(
customer_id: &id_type::GlobalCustomerId,
pmd: hyperswitch_domain_models::vault::PaymentMethodVaultingData,
ttl: i64,
+ vault_id: Option<domain::VaultId>,
) -> errors::CustomResult<Vec<u8>, errors::VaultError> {
+ let vault_id =
+ vault_id.unwrap_or_else(|| domain::VaultId::generate(uuid::Uuid::now_v7().to_string()));
+
if should_trigger_fingerprint_migration {
pm_types::AddVaultRequestNew {
entity_id: merchant_id,
- vault_id: domain::VaultId::generate(uuid::Uuid::now_v7().to_string()),
+ vault_id,
data: pmd,
ttl,
}
@@ -1958,7 +1979,7 @@ pub fn encode_add_vault_request(
} else {
pm_types::AddVaultRequest {
entity_id: customer_id.clone(),
- vault_id: domain::VaultId::generate(uuid::Uuid::now_v7().to_string()),
+ vault_id,
data: pmd,
ttl,
}
diff --git a/crates/router/src/core/payment_methods/vault.rs b/crates/router/src/core/payment_methods/vault.rs
index c98fcdbfbc..8abfdc94fb 100644
--- a/crates/router/src/core/payment_methods/vault.rs
+++ b/crates/router/src/core/payment_methods/vault.rs
@@ -2086,6 +2086,7 @@ pub async fn add_payment_method_to_vault(
customer_id,
pmd.clone(),
state.conf.locker.ttl_for_storage_in_secs,
+ existing_vault_id,
)?;
let query_params = write_mode.map(pm_types::VaultQueryParam::from);
diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rs
index c2b23802d6..1206cccc60 100644
--- a/crates/router/src/core/payments/helpers.rs
+++ b/crates/router/src/core/payments/helpers.rs
@@ -2143,6 +2143,24 @@ pub async fn create_customer_if_not_exist<'a, F: Clone, R, D>(
}
}
None => {
+ let pm_modular_dimensions = dimensions
+ .without_profile_id()
+ .with_organization_id(provider.get_account().organization_id.clone())
+ .without_provider_merchant_id()
+ .without_processor_merchant_id();
+ let should_call_pm_modular_service =
+ payment_methods::utils::get_organization_eligibility_config_for_pm_modular_service(
+ state,
+ &pm_modular_dimensions,
+ )
+ .await;
+
+ if should_call_pm_modular_service {
+ Err(report!(errors::StorageError::ValueNotFound(
+ "customer".to_owned()
+ )))?
+ }
+
// Validate that the customer_id is not in GlobalCustomerId format
if customers::is_customer_id_in_global_format(&customer_id) {
Err(report!(errors::StorageError::InvalidDataFormat(format!(
diff --git a/crates/router/src/types/payment_methods.rs b/crates/router/src/types/payment_methods.rs
index 4100f0e55e..c1f372519a 100644
--- a/crates/router/src/types/payment_methods.rs
+++ b/crates/router/src/types/payment_methods.rs
@@ -53,6 +53,15 @@ pub struct AddVaultRequest<D> {
pub ttl: i64,
}
+#[cfg(feature = "v1")]
+#[derive(Debug, serde::Deserialize, serde::Serialize)]
+pub struct AddCompatVaultRequest<D> {
+ pub entity_id: id_type::CustomerId,
+ pub vault_id: domain::VaultId,
+ pub data: D,
+ pub ttl: i64,
+}
+
#[derive(Debug, serde::Deserialize, serde::Serialize)]
pub struct AddVaultRequestNew<D> {
pub entity_id: id_type::MerchantId,
diff --git a/crates/router/src/workflows/payment_method_modular_forward_compat.rs b/crates/router/src/workflows/payment_method_modular_forward_compat.rs
index d533ea2ea2..b6465817ce 100644
--- a/crates/router/src/workflows/payment_method_modular_forward_compat.rs
+++ b/crates/router/src/workflows/payment_method_modular_forward_compat.rs
@@ -141,6 +141,7 @@ impl ProcessTrackerWorkflow<SessionState> for PaymentMethodModularForwardCompatW
&customer_id,
pmd,
state.conf.locker.ttl_for_storage_in_secs,
+ Some(domain::VaultId::generate(card_reference.clone())),
)
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable(