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(payments): configure cross-currency MIT validation (#15320)

Amitsingh Tanwara3d1382bd677
diff --git a/config/config.example.toml b/config/config.example.toml
index f994a0d9b5..b2eb104307 100644
--- a/config/config.example.toml
+++ b/config/config.example.toml
@@ -790,6 +790,16 @@ bank_transfer.pix_automatico_push = { connector_list = "santander" }
bank_transfer.pix_automatico_qr = { connector_list = "santander" }
network_token.network_token.connector_list = "peachpayments"
+# Listed connectors may reuse connector mandates across currencies, subject to currency rules.
+# Applies across payment methods and currencies. Confirm connector/account support before enabling.
+[mandates.cross_currency_mit_supported_connectors]
+connector_list = ["datatrans", "stripe"]
+# Optional rules by connector and payment-method type; both currencies must be listed.
+# Missing or empty rules use pm_filters for the requested currency; absent filters allow it.
+# [mandates.cross_currency_mit_supported_connectors.currency_rules.stripe]
+# credit = ["USD", "CAD"]
+# debit = ["USD", "CAD"]
+
[mandates.supported_payment_methods]
card.credit.connector_list = "aci,checkout,stripe,adyen,authorizedotnet,cybersource,datatrans,globalpay,worldpay,multisafepay,nmi,nexinets,noon,bankofamerica,braintree,nuvei,payme,wellsfargo,bamboraapac,elavon,fiuu,nexixpay,novalnet,paybox,paypal,xendit,moneris,archipel,worldpayvantiv,mollie,airwallex,peachpayments,imerchantsolutions,givepayments,shift4,jpmorgan,ecommpay,worldpayraft,elavon_pg"
card.debit.connector_list = "aci,checkout,stripe,adyen,authorizedotnet,cybersource,datatrans,globalpay,worldpay,multisafepay,nmi,nexinets,noon,bankofamerica,braintree,nuvei,payme,wellsfargo,bamboraapac,elavon,fiuu,nexixpay,novalnet,paybox,paypal,xendit,moneris,archipel,worldpayvantiv,mollie,airwallex,peachpayments,imerchantsolutions,givepayments,shift4,jpmorgan,ecommpay,worldpayraft,elavon_pg"
diff --git a/config/development.toml b/config/development.toml
index e006fdcdf2..f662041860 100644
--- a/config/development.toml
+++ b/config/development.toml
@@ -1403,6 +1403,14 @@ bank_transfer.pix_automatico_qr = { connector_list = "santander" }
network_token.network_token.connector_list = "peachpayments"
+[mandates.cross_currency_mit_supported_connectors]
+connector_list = ["datatrans", "stripe"]
+# Optional rules by connector and payment-method type; both currencies must be listed.
+# Missing or empty rules use pm_filters for the requested currency; absent filters allow it.
+# [mandates.cross_currency_mit_supported_connectors.currency_rules.stripe]
+# credit = ["USD", "CAD"]
+# debit = ["USD", "CAD"]
+
[mandates.supported_payment_methods]
bank_debit.ach = { connector_list = "gocardless,adyen,stripe,payload" }
bank_debit.becs = { connector_list = "gocardless,stripe,adyen" }
diff --git a/crates/payment_methods/src/configs/payment_connector_required_fields.rs b/crates/payment_methods/src/configs/payment_connector_required_fields.rs
index ae1a7b9a13..519d5b6efe 100644
--- a/crates/payment_methods/src/configs/payment_connector_required_fields.rs
+++ b/crates/payment_methods/src/configs/payment_connector_required_fields.rs
@@ -24,6 +24,7 @@ impl Default for ZeroMandates {
impl Default for Mandates {
fn default() -> Self {
Self {
+ cross_currency_mit_supported_connectors: Default::default(),
supported_payment_methods: SupportedPaymentMethodsForMandate(HashMap::from([
(
enums::PaymentMethod::PayLater,
diff --git a/crates/payment_methods/src/configs/settings.rs b/crates/payment_methods/src/configs/settings.rs
index a84a2fa08d..f8f99f3e22 100644
--- a/crates/payment_methods/src/configs/settings.rs
+++ b/crates/payment_methods/src/configs/settings.rs
@@ -139,8 +139,21 @@ impl InstallmentConfig {
}
}
+/// Connectors for which connector mandates may be reused across currencies.
+#[derive(Debug, Deserialize, Clone, Default)]
+#[serde(default, deny_unknown_fields)]
+pub struct CrossCurrencyMitSupportedConnectors {
+ pub connector_list: HashSet<enums::Connector>,
+ pub currency_rules: CrossCurrencyMitCurrencyRules,
+}
+
+pub type CrossCurrencyMitCurrencyRules =
+ HashMap<enums::Connector, HashMap<enums::PaymentMethodType, HashSet<enums::Currency>>>;
+
#[derive(Debug, Deserialize, Clone)]
pub struct Mandates {
+ #[serde(default)]
+ pub cross_currency_mit_supported_connectors: CrossCurrencyMitSupportedConnectors,
pub supported_payment_methods: SupportedPaymentMethodsForMandate,
pub update_mandate_supported: SupportedPaymentMethodsForMandate,
}
diff --git a/crates/router/src/configs/settings.rs b/crates/router/src/configs/settings.rs
index 379011227d..ff9bc3b496 100644
--- a/crates/router/src/configs/settings.rs
+++ b/crates/router/src/configs/settings.rs
@@ -38,9 +38,10 @@ use hyperswitch_masking::{Maskable, PeekInterface, Secret};
pub use payment_methods::configs::{
settings::{
BankRedirectConfig, BanksVector, ConnectorBankNames, ConnectorFields,
- EligiblePaymentMethods, InstallmentConfig, Installments, Mandates, PaymentMethodAuth,
- PaymentMethodType, RequiredFieldFinal, RequiredFields, SupportedConnectorsForMandate,
- SupportedPaymentMethodTypesForMandate, SupportedPaymentMethodsForMandate, ZeroMandates,
+ CrossCurrencyMitSupportedConnectors, EligiblePaymentMethods, InstallmentConfig,
+ Installments, Mandates, PaymentMethodAuth, PaymentMethodType, RequiredFieldFinal,
+ RequiredFields, SupportedConnectorsForMandate, SupportedPaymentMethodTypesForMandate,
+ SupportedPaymentMethodsForMandate, ZeroMandates,
},
AuthenticationServiceConfig, MicroServicesConfig,
};
@@ -1576,6 +1577,7 @@ impl Settings<SecuredSecret> {
.with_list_parse_key("redis.cluster_urls")
.with_list_parse_key("events.kafka.brokers")
.with_list_parse_key("connectors.supported.wallets")
+ .with_list_parse_key("mandates.cross_currency_mit_supported_connectors.connector_list")
.with_list_parse_key("report_download_config.process_tracker.email_bcc")
.with_list_parse_key("report_download_config.process_tracker_reports")
.with_list_parse_key("connector_request_reference_id_config.merchant_ids_send_payment_id_as_connector_request_id");
diff --git a/crates/router/src/core/payments.rs b/crates/router/src/core/payments.rs
index e8c8fc077d..7adf28d468 100644
--- a/crates/router/src/core/payments.rs
+++ b/crates/router/src/core/payments.rs
@@ -119,6 +119,8 @@ use super::{
},
};
#[cfg(feature = "v1")]
+use crate::configs::settings::{ConnectorFilters, CrossCurrencyMitSupportedConnectors};
+#[cfg(feature = "v1")]
use crate::core::blocklist::utils as blocklist_utils;
#[cfg(feature = "v1")]
use crate::core::card_testing_guard::utils as card_testing_guard_utils;
@@ -12968,6 +12970,8 @@ where
chosen_connector_routing_data.clone(),
payment_data,
&payment_method_info,
+ &state.conf.mandates.cross_currency_mit_supported_connectors,
+ &state.conf.pm_filters,
)?;
routing_data.routed_through = Some(
@@ -12996,6 +13000,8 @@ pub fn get_mandate_reference_id<F: Clone, D>(
connector_routing_data: api::ConnectorRoutingData,
payment_data: &mut D,
payment_method_info: &domain::PaymentMethod,
+ cross_currency_mit_supported_connectors: &CrossCurrencyMitSupportedConnectors,
+ pm_filters: &ConnectorFilters,
) -> RouterResult<Option<mandates::MandateReferenceId>>
where
D: OperationSessionGetters<F> + OperationSessionSetters<F> + Send + Sync + Clone,
@@ -13038,15 +13044,17 @@ where
mandate_reference_record,
)?;
- if let Some(mandate_currency) =
- mandate_reference_record.original_payment_authorized_currency
- {
- if mandate_currency != payment_data.get_currency() {
- return Err(report!(errors::ApiErrorResponse::MandateValidationFailed {
- reason: "Cross currency mandates not supported".into(),
- }));
- }
- }
+ helpers::validate_connector_mandate_currency(
+ cross_currency_mit_supported_connectors,
+ pm_filters,
+ connector_routing_data.connector_data.connector_name,
+ payment_data
+ .get_payment_attempt()
+ .payment_method_type
+ .or(payment_method_info.get_payment_method_subtype()),
+ mandate_reference_record.original_payment_authorized_currency,
+ payment_data.get_currency(),
+ )?;
payment_data.set_recurring_mandate_payment_data(mandate_reference_record.into());
@@ -13117,16 +13125,14 @@ where
mandate_reference_record,
)?;
- common_utils::fp_utils::when(
- mandate_reference_record
- .original_payment_authorized_currency
- .map(|mandate_currency| mandate_currency != payment_data.get_currency())
- .unwrap_or(false),
- || {
- Err(report!(errors::ApiErrorResponse::MandateValidationFailed {
- reason: "cross currency mandates not supported".into()
- }))
- },
+ helpers::validate_connector_mandate_currency(
+ &state.conf.mandates.cross_currency_mit_supported_connectors,
+ &state.conf.pm_filters,
+ connector_data.connector_name,
+ payment_data.get_payment_attempt().payment_method_type
+ .or(payment_method_info.get_payment_method_subtype()),
+ mandate_reference_record.original_payment_authorized_currency,
+ payment_data.get_currency(),
)?;
let mandate_reference_id = Some(mandates::MandateReferenceId::ConnectorMandateId(
mandates::ConnectorMandateReferenceId::new(
diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rs
index cfff669f6f..e55bb19fc8 100644
--- a/crates/router/src/core/payments/helpers.rs
+++ b/crates/router/src/core/payments/helpers.rs
@@ -80,6 +80,10 @@ use super::{
CustomerDetails, PaymentData,
};
#[cfg(feature = "v1")]
+use crate::configs::settings::{
+ ConnectorFilters, CrossCurrencyMitSupportedConnectors, PaymentMethodFilterKey,
+};
+#[cfg(feature = "v1")]
use crate::core::mandate::helpers::MandateGenericData;
#[cfg(feature = "v1")]
use crate::core::{
@@ -1457,6 +1461,103 @@ fn validate_recurring_mandate(req: api::MandateValidationFields) -> RouterResult
}
}
+/// Validate connector mandate currency on initial attempts and retries.
+#[cfg(feature = "v1")]
+pub(super) fn validate_connector_mandate_currency(
+ config: &CrossCurrencyMitSupportedConnectors,
+ pm_filters: &ConnectorFilters,
+ connector: api_enums::Connector,
+ payment_method_type: Option<api_enums::PaymentMethodType>,
+ original_currency: Option<api_enums::Currency>,
+ payment_currency: api_enums::Currency,
+) -> RouterResult<()> {
+ match original_currency {
+ Some(original_currency) if original_currency == payment_currency => Ok(()),
+ Some(original_currency) => match is_cross_currency_mit_allowed(
+ config,
+ pm_filters,
+ connector,
+ payment_method_type,
+ original_currency,
+ payment_currency,
+ ) {
+ true => {
+ logger::info!(
+ %connector,
+ ?payment_method_type,
+ %original_currency,
+ %payment_currency,
+ "allowing cross-currency connector mandate"
+ );
+ Ok(())
+ }
+ false => Err(report!(errors::ApiErrorResponse::MandateValidationFailed {
+ reason: "Cross currency mandates not supported".into(),
+ })),
+ },
+ None => Ok(()),
+ }
+}
+
+/// Connector opt-in is required before applying explicit currency rules or the PM fallback.
+#[cfg(feature = "v1")]
+fn is_cross_currency_mit_allowed(
+ config: &CrossCurrencyMitSupportedConnectors,
+ pm_filters: &ConnectorFilters,
+ connector: api_enums::Connector,
+ payment_method_type: Option<api_enums::PaymentMethodType>,
+ original_currency: api_enums::Currency,
+ payment_currency: api_enums::Currency,
+) -> bool {
+ match config.connector_list.contains(&connector) {
+ true => {
+ let currency_rule = payment_method_type
+ .and_then(|method| config.currency_rules.get(&connector)?.get(&method))
+ .filter(|currencies| !currencies.is_empty());
+ match currency_rule {
+ Some(currencies) => {
+ currencies.contains(&original_currency)
+ && currencies.contains(&payment_currency)
+ }
+ None => is_payment_currency_allowed_by_pm_filters(
+ pm_filters,
+ connector,
+ payment_method_type,
+ payment_currency,
+ ),
+ }
+ }
+ false => false,
+ }
+}
+
+/// Resolve connector-specific PM rules before defaults; absent currency restrictions allow payment.
+#[cfg(feature = "v1")]
+fn is_payment_currency_allowed_by_pm_filters(
+ pm_filters: &ConnectorFilters,
+ connector: api_enums::Connector,
+ payment_method_type: Option<api_enums::PaymentMethodType>,
+ payment_currency: api_enums::Currency,
+) -> bool {
+ let filter = payment_method_type.and_then(|method| {
+ let key = PaymentMethodFilterKey::PaymentMethodType(method);
+ pm_filters
+ .0
+ .get(&connector.to_string())
+ .and_then(|filters| filters.0.get(&key))
+ .or_else(|| {
+ pm_filters
+ .0
+ .get("default")
+ .and_then(|filters| filters.0.get(&key))
+ })
+ });
+ match filter.and_then(|filter| filter.currency.as_ref()) {
+ Some(currencies) => currencies.contains(&payment_currency),
+ None => true,
+ }
+}
+
pub fn verify_mandate_details(
request_amount: MinorUnit,
request_currency: api_enums::Currency,
diff --git a/crates/router/src/core/payments/retry.rs b/crates/router/src/core/payments/retry.rs
index 16d248a300..e81613b496 100644
--- a/crates/router/src/core/payments/retry.rs
+++ b/crates/router/src/core/payments/retry.rs
@@ -205,6 +205,8 @@ where
connector_routing_data.clone(),
payment_data,
&payment_method_info,
+ &state.conf.mandates.cross_currency_mit_supported_connectors,
+ &state.conf.pm_filters,
)?;
payment_data.set_mandate_id(mandates::MandateIds {
mandate_id: None,