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(payouts): support currency-wise min and max amount configs (#15199)

Sayak Bhattacharya2a7db7c6c58e
diff --git a/config/superposition_seed.toml b/config/superposition_seed.toml
index c83fba01a3..d9985f40a3 100644
--- a/config/superposition_seed.toml
+++ b/config/superposition_seed.toml
@@ -2567,8 +2567,8 @@ client_session_validation_enabled = { value = true, schema = { type = "boolean"
"webhooks.unverified_webhook_profile_rate_limit" = { value = 0, schema = { maximum = 4294967295, minimum = 0, type = "integer" }, description = "Maximum unverified incoming webhooks per profile per window, 0 disables the profile level", change_reason = "Unverified webhook rate limiting" }
"webhooks.unverified_webhook_merchant_connector_account_rate_limit" = { value = 0, schema = { maximum = 4294967295, minimum = 0, type = "integer" }, description = "Maximum unverified incoming webhooks per merchant connector account per window, 0 disables the merchant connector account level", change_reason = "Unverified webhook rate limiting" }
"payouts.max_auto_payout_retries" = { value = 0, schema = { maximum = 4294967295, minimum = 0, type = "integer" }, description = "Maximum auto payout retries, differentiated by payout_retry_type dimension (single_connector or multi_connector)", change_reason = "Initial setup" }
-"payouts.min_amount" = { value = 0, schema = { maximum = 999999999, minimum = 0, type = "integer" }, description = "Minimum payout amount in the currency's lowest denomination. Override with organization_id, processor_merchant_id, and profile_id to set scoped caps.", change_reason = "Add organization-merchant-profile-configurable payout minimum amount" }
-"payouts.max_amount" = { value = 999999999, schema = { maximum = 999999999, minimum = 0, type = "integer" }, description = "Maximum payout amount in the currency's lowest denomination. Override with organization_id, processor_merchant_id, and profile_id to set scoped caps.", change_reason = "Add organization-merchant-profile-configurable payout maximum amount" }
+"payouts.min_amount" = { value = 0, schema = { type = "integer", maximum = 999999999, minimum = 0 }, description = "Minimum payout amount in the destination currency's lowest denomination. Override by currency, organization_id, processor_merchant_id, and profile_id.", change_reason = "Add currency and organization-merchant-profile-scoped payout minimum amounts" }
+"payouts.max_amount" = { value = 999999999, schema = { type = "integer", maximum = 999999999, minimum = 0 }, description = "Maximum payout amount in the destination currency's lowest denomination. Override by currency, organization_id, processor_merchant_id, and profile_id.", change_reason = "Add currency and organization-merchant-profile-scoped payout maximum amounts" }
"payouts.payout_frm_call" = { value = false, schema = { type = "boolean" }, description = "Whether to call FRM for payouts", change_reason = "Initial setup" }
"payouts.rerun_payout_frm_before_auto_retry" = { value = false, schema = { type = "boolean" }, description = "Whether to rerun payout FRM before automatic retries, overridable by the retry connector", change_reason = "Gate payout FRM reruns on automatic retries" }
"payouts.payout_blocklist_guard" = { value = false, schema = { type = "boolean" }, description = "Whether to check card payouts against the blocklist and the profile's card blocking rules", change_reason = "Initial setup" }
diff --git a/crates/router/src/core/configs/dimension_config.rs b/crates/router/src/core/configs/dimension_config.rs
index fba307a39e..d67fa8ace5 100644
--- a/crates/router/src/core/configs/dimension_config.rs
+++ b/crates/router/src/core/configs/dimension_config.rs
@@ -731,7 +731,8 @@ config! {
superposition_key = PAYOUT_MIN_AMOUNT,
output = common_utils::types::MinorUnit,
default = common_utils::types::MinorUnit::zero(),
- requires = dimension_state::DimensionsWithProcessorAndProviderMerchantIdAndOrgIdAndProfileId,
+ generics = [Pm, M, P, Cn, PRT, Ev, Pmt],
+ requires = dimension_state::Dimensions<Pm, M, dimension_state::HasOrgId, P, Cn, PRT, Ev, Pmt>,
targeting_key = id_type::ProfileId
}
@@ -743,7 +744,8 @@ config! {
superposition_key = PAYOUT_MAX_AMOUNT,
output = common_utils::types::MinorUnit,
default = common_utils::types::MinorUnit::new(crate::consts::MAX_ALLOWED_AMOUNT),
- requires = dimension_state::DimensionsWithProcessorAndProviderMerchantIdAndOrgIdAndProfileId,
+ generics = [Pm, M, P, Cn, PRT, Ev, Pmt],
+ requires = dimension_state::Dimensions<Pm, M, dimension_state::HasOrgId, P, Cn, PRT, Ev, Pmt>,
targeting_key = id_type::ProfileId
}
diff --git a/crates/router/src/core/configs/dimension_state.rs b/crates/router/src/core/configs/dimension_state.rs
index ba5eff8810..8d778dcdaa 100644
--- a/crates/router/src/core/configs/dimension_state.rs
+++ b/crates/router/src/core/configs/dimension_state.rs
@@ -1,7 +1,7 @@
use std::marker::PhantomData;
use api_models::webhooks::IncomingWebhookEvent;
-use common_enums::{connector_enums::Connector, PaymentMethodType, PayoutRetryType};
+use common_enums::{connector_enums::Connector, Currency, PaymentMethodType, PayoutRetryType};
use common_utils::id_type;
use external_services::superposition;
use heck::ToPascalCase;
@@ -115,6 +115,7 @@ pub struct Dimensions<Pm, M, O, P, Cn, PRT, Ev, Pmt> {
payout_retry_type: Option<PayoutRetryType>,
incoming_webhook_event: Option<IncomingWebhookEvent>,
payment_method_type: Option<PaymentMethodType>,
+ currency: Option<Currency>,
_phantom: DimensionMarkers<Pm, M, O, P, Cn, PRT, Ev, Pmt>,
}
@@ -140,6 +141,7 @@ impl
payout_retry_type: None,
incoming_webhook_event: None,
payment_method_type: None,
+ currency: None,
_phantom: PhantomData,
}
}
@@ -160,6 +162,7 @@ impl<M, O, P, Cn, PRT, Ev, Pmt> Dimensions<NoProviderMerchantId, M, O, P, Cn, PR
payout_retry_type: self.payout_retry_type.clone(),
incoming_webhook_event: self.incoming_webhook_event,
payment_method_type: self.payment_method_type,
+ currency: self.currency,
_phantom: PhantomData,
}
}
@@ -180,6 +183,7 @@ impl<Pm, O, P, Cn, PRT, Ev, Pmt> Dimensions<Pm, NoProcessorMerchantId, O, P, Cn,
payout_retry_type: self.payout_retry_type.clone(),
incoming_webhook_event: self.incoming_webhook_event,
payment_method_type: self.payment_method_type,
+ currency: self.currency,
_phantom: PhantomData,
}
}
@@ -200,6 +204,7 @@ impl<Pm, M, P, Cn, PRT, Ev, Pmt> Dimensions<Pm, M, NoOrgId, P, Cn, PRT, Ev, Pmt>
payout_retry_type: self.payout_retry_type.clone(),
incoming_webhook_event: self.incoming_webhook_event,
payment_method_type: self.payment_method_type,
+ currency: self.currency,
_phantom: PhantomData,
}
}
@@ -220,6 +225,7 @@ impl<Pm, M, O, Cn, PRT, Ev, Pmt> Dimensions<Pm, M, O, NoProfileId, Cn, PRT, Ev,
payout_retry_type: self.payout_retry_type.clone(),
incoming_webhook_event: self.incoming_webhook_event,
payment_method_type: self.payment_method_type,
+ currency: self.currency,
_phantom: PhantomData,
}
}
@@ -240,6 +246,7 @@ impl<Pm, M, O, P, PRT, Ev, Pmt> Dimensions<Pm, M, O, P, NoConnector, PRT, Ev, Pm
payout_retry_type: self.payout_retry_type.clone(),
incoming_webhook_event: self.incoming_webhook_event,
payment_method_type: self.payment_method_type,
+ currency: self.currency,
_phantom: PhantomData,
}
}
@@ -260,6 +267,7 @@ impl<Pm, M, O, P, Cn, Ev, Pmt> Dimensions<Pm, M, O, P, Cn, NoPayoutRetryType, Ev
payout_retry_type: Some(retry_type),
incoming_webhook_event: self.incoming_webhook_event,
payment_method_type: self.payment_method_type,
+ currency: self.currency,
_phantom: PhantomData,
}
}
@@ -280,6 +288,7 @@ impl<Pm, M, O, P, Cn, PRT, Pmt> Dimensions<Pm, M, O, P, Cn, PRT, NoWebhookEvent,
payout_retry_type: self.payout_retry_type.clone(),
incoming_webhook_event: Some(event),
payment_method_type: self.payment_method_type,
+ currency: self.currency,
_phantom: PhantomData,
}
}
@@ -300,6 +309,25 @@ impl<Pm, M, O, P, Cn, PRT, Ev> Dimensions<Pm, M, O, P, Cn, PRT, Ev, NoPaymentMet
payout_retry_type: self.payout_retry_type.clone(),
incoming_webhook_event: self.incoming_webhook_event,
payment_method_type: Some(payment_method_type),
+ currency: self.currency,
+ _phantom: PhantomData,
+ }
+ }
+}
+
+impl<Pm, M, O, P, Cn, PRT, Ev, Pmt> Dimensions<Pm, M, O, P, Cn, PRT, Ev, Pmt> {
+ /// Adds currency to the Superposition context.
+ pub fn with_currency(&self, currency: Currency) -> Self {
+ Self {
+ provider_merchant_id: self.provider_merchant_id.clone(),
+ processor_merchant_id: self.processor_merchant_id.clone(),
+ organization_id: self.organization_id.clone(),
+ profile_id: self.profile_id.clone(),
+ connector: self.connector,
+ payout_retry_type: self.payout_retry_type.clone(),
+ incoming_webhook_event: self.incoming_webhook_event,
+ payment_method_type: self.payment_method_type,
+ currency: Some(currency),
_phantom: PhantomData,
}
}
@@ -319,6 +347,7 @@ impl<M, O, P, Cn, PRT, Ev, Pmt> Dimensions<HasProviderMerchantId, M, O, P, Cn, P
payout_retry_type: self.payout_retry_type.clone(),
incoming_webhook_event: self.incoming_webhook_event,
payment_method_type: self.payment_method_type,
+ currency: self.currency,
_phantom: PhantomData,
}
}
@@ -338,6 +367,7 @@ impl<Pm, O, P, Cn, PRT, Ev, Pmt> Dimensions<Pm, HasProcessorMerchantId, O, P, Cn
payout_retry_type: self.payout_retry_type.clone(),
incoming_webhook_event: self.incoming_webhook_event,
payment_method_type: self.payment_method_type,
+ currency: self.currency,
_phantom: PhantomData,
}
}
@@ -355,6 +385,7 @@ impl<Pm, M, P, Cn, PRT, Ev, Pmt> Dimensions<Pm, M, HasOrgId, P, Cn, PRT, Ev, Pmt
payout_retry_type: self.payout_retry_type.clone(),
incoming_webhook_event: self.incoming_webhook_event,
payment_method_type: self.payment_method_type,
+ currency: self.currency,
_phantom: PhantomData,
}
}
@@ -372,6 +403,7 @@ impl<Pm, M, O, Cn, PRT, Ev, Pmt> Dimensions<Pm, M, O, HasProfileId, Cn, PRT, Ev,
payout_retry_type: self.payout_retry_type.clone(),
incoming_webhook_event: self.incoming_webhook_event,
payment_method_type: self.payment_method_type,
+ currency: self.currency,
_phantom: PhantomData,
}
}
@@ -389,6 +421,7 @@ impl<Pm, M, O, P, PRT, Ev, Pmt> Dimensions<Pm, M, O, P, HasConnector, PRT, Ev, P
payout_retry_type: self.payout_retry_type.clone(),
incoming_webhook_event: self.incoming_webhook_event,
payment_method_type: self.payment_method_type,
+ currency: self.currency,
_phantom: PhantomData,
}
}
@@ -408,6 +441,7 @@ impl<Pm, M, O, P, Cn, PRT, Pmt> Dimensions<Pm, M, O, P, Cn, PRT, HasWebhookEvent
payout_retry_type: self.payout_retry_type.clone(),
incoming_webhook_event: None,
payment_method_type: self.payment_method_type,
+ currency: self.currency,
_phantom: PhantomData,
}
}
@@ -545,6 +579,10 @@ impl<Pm, M, O, P, Cn, PRT, Ev, Pmt> Dimensions<Pm, M, O, P, Cn, PRT, Ev, Pmt> {
);
}
+ if let Some(currency) = self.currency {
+ ctx = ctx.with("currency", currency.to_string().as_str());
+ }
+
Some(ctx)
}
}
diff --git a/crates/router/src/core/payouts/helpers.rs b/crates/router/src/core/payouts/helpers.rs
index 88e1dee1fc..9c58fad66b 100644
--- a/crates/router/src/core/payouts/helpers.rs
+++ b/crates/router/src/core/payouts/helpers.rs
@@ -1463,6 +1463,7 @@ pub async fn update_payouts_and_payout_attempt(
}));
}
+ let payouts = payout_data.payouts.to_owned();
let profile_id = payout_data.business_profile.get_id();
let payout_cap_dimensions = dimension_state::Dimensions::new()
.with_processor_merchant_id(platform.get_processor().get_processor_merchant_id())
@@ -1479,7 +1480,8 @@ pub async fn update_payouts_and_payout_attempt(
state,
&payout_cap_dimensions,
profile_id,
- req.amount,
+ Some(req.amount.unwrap_or(payouts.amount.into())),
+ Some(req.currency.unwrap_or(payouts.destination_currency)),
)
.await?;
@@ -1516,7 +1518,6 @@ pub async fn update_payouts_and_payout_attempt(
payout_data.billing_address = billing_address;
// Update DB with new data
- let payouts = payout_data.payouts.to_owned();
let amount = MinorUnit::from(req.amount.unwrap_or(payouts.amount.into()));
let funds_transfer_type = req.funds_transfer_type.or(payouts.funds_transfer_type);
let sender_details = req
diff --git a/crates/router/src/core/payouts/proxy.rs b/crates/router/src/core/payouts/proxy.rs
index 53405fd946..7424c451fd 100644
--- a/crates/router/src/core/payouts/proxy.rs
+++ b/crates/router/src/core/payouts/proxy.rs
@@ -569,6 +569,7 @@ impl ExternalVaultPayout<'_> {
&payout_cap_dimensions,
profile.get_id(),
req.amount,
+ req.currency,
)
.await?;
let customer_id = req.get_customer_id().get_required_value("customer_id")?;
diff --git a/crates/router/src/core/payouts/validator.rs b/crates/router/src/core/payouts/validator.rs
index fc824c9475..7b884c4eb0 100644
--- a/crates/router/src/core/payouts/validator.rs
+++ b/crates/router/src/core/payouts/validator.rs
@@ -199,8 +199,14 @@ pub async fn validate_create_request(
)
.with_profile_id(profile_id.clone());
- validate_payout_amount_against_config(state, &profile_dimensions, &profile_id, req.amount)
- .await?;
+ validate_payout_amount_against_config(
+ state,
+ &profile_dimensions,
+ &profile_id,
+ req.amount,
+ req.currency,
+ )
+ .await?;
// Payout ID
let db: &dyn StorageInterface = &*state.store;
@@ -383,26 +389,29 @@ pub(crate) async fn validate_payout_amount_against_config(
dimensions: &dimension_state::DimensionsWithProcessorAndProviderMerchantIdAndOrgIdAndProfileId,
profile_id: &id_type::ProfileId,
amount: Option<Amount>,
+ currency: Option<common_enums::Currency>,
) -> RouterResult<()> {
- let min_amount = dimensions
- .get_payout_min_amount(
- state.store.as_ref(),
- state.superposition_service.as_ref(),
- Some(profile_id),
- )
- .await;
- let max_amount = dimensions
- .get_payout_max_amount(
- state.store.as_ref(),
- state.superposition_service.as_ref(),
- Some(profile_id),
- )
- .await;
+ if let Some((amount, currency)) = amount.zip(currency) {
+ let currency_dimensions = dimensions.with_currency(currency);
+ let min_amount = currency_dimensions
+ .get_payout_min_amount(
+ state.store.as_ref(),
+ state.superposition_service.as_ref(),
+ Some(profile_id),
+ )
+ .await;
+ let max_amount = currency_dimensions
+ .get_payout_max_amount(
+ state.store.as_ref(),
+ state.superposition_service.as_ref(),
+ Some(profile_id),
+ )
+ .await;
- amount
- .map(|amount| validate_payout_amount(amount, min_amount, max_amount))
- .transpose()
- .map(|_| ())
+ validate_payout_amount(amount, min_amount, max_amount)
+ } else {
+ Ok(())
+ }
}
#[cfg(feature = "v1")]