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(superposition): max payout retry superpostion config changes (#11470)

Sagar naik300d8fd52233
diff --git a/config/superposition_seed.toml b/config/superposition_seed.toml
index 5d944b2fcc..f262346110 100644
--- a/config/superposition_seed.toml
+++ b/config/superposition_seed.toml
@@ -40,6 +40,12 @@ schema = { type = "string" }
description = "Payment connector identifier (e.g. stripe, adyen)"
change_reason = "Initial setup"
+[dimensions.payout_retry_type]
+position = 6
+schema = { type = "string" }
+description = "Type of payout retry (single_connector or multi_connector)"
+change_reason = "Initial setup"
+
[default-configs.requires_cvv]
value = true
schema = { type = "boolean" }
@@ -97,3 +103,9 @@ schema = { type = "boolean" }
description = "Whether to use extended card BIN (8-digit) for payment method data"
change_reason = "Initial setup"
+[default-configs.max_auto_payout_retries]
+value = 0
+schema = { type = "integer", minimum = 0, maximum = 4294967295 }
+description = "Maximum auto payout retries, differentiated by payout_retry_type dimension (single_connector or multi_connector)"
+change_reason = "Initial setup"
+
diff --git a/crates/common_enums/src/enums.rs b/crates/common_enums/src/enums.rs
index 994bda4fd5..6b3dfab0e5 100644
--- a/crates/common_enums/src/enums.rs
+++ b/crates/common_enums/src/enums.rs
@@ -9946,8 +9946,9 @@ pub enum EntityType {
Profile = 0,
}
-#[derive(Clone, Debug, serde::Serialize)]
+#[derive(Clone, Debug, serde::Serialize, strum::Display)]
#[serde(rename_all = "snake_case")]
+#[strum(serialize_all = "snake_case")]
pub enum PayoutRetryType {
SingleConnector,
MultiConnector,
diff --git a/crates/common_utils/src/id_type/merchant.rs b/crates/common_utils/src/id_type/merchant.rs
index b177d0b285..659f18a3bd 100644
--- a/crates/common_utils/src/id_type/merchant.rs
+++ b/crates/common_utils/src/id_type/merchant.rs
@@ -216,22 +216,6 @@ impl MerchantId {
)
}
- /// get_max_auto_single_connector_payout_retries_enabled_
- pub fn get_max_auto_single_connector_payout_retries_enabled(
- &self,
- payout_retry_type: common_enums::PayoutRetryType,
- ) -> String {
- match payout_retry_type {
- common_enums::PayoutRetryType::SingleConnector => format!(
- "max_auto_single_connector_payout_retries_enabled_{}",
- self.get_string_repr()
- ),
- common_enums::PayoutRetryType::MultiConnector => format!(
- "max_auto_multiple_connector_payout_retries_enabled_{}",
- self.get_string_repr()
- ),
- }
- }
/// get_authentication_service_eligible_key
pub fn get_authentication_service_eligible_key(&self) -> String {
format!("authentication_service_eligible_{}", self.get_string_repr())
diff --git a/crates/external_services/src/superposition.rs b/crates/external_services/src/superposition.rs
index 41a9d5b7e1..5c8bd1db5a 100644
--- a/crates/external_services/src/superposition.rs
+++ b/crates/external_services/src/superposition.rs
@@ -72,6 +72,22 @@ impl GetValue<i64> for open_feature::Client {
}
}
+impl GetValue<u32> for open_feature::Client {
+ async fn get_value(
+ &self,
+ key: &str,
+ context: &open_feature::EvaluationContext,
+ ) -> Result<u32, open_feature::EvaluationError> {
+ let value = self.get_int_value(key, Some(context), None).await?;
+ u32::try_from(value).map_err(|err| {
+ open_feature::EvaluationError::builder()
+ .code(open_feature::EvaluationErrorCode::TypeMismatch)
+ .message(err.to_string())
+ .build()
+ })
+ }
+}
+
impl GetValue<f64> for open_feature::Client {
async fn get_value(
&self,
diff --git a/crates/router/src/consts.rs b/crates/router/src/consts.rs
index 6c69cba107..e018653317 100644
--- a/crates/router/src/consts.rs
+++ b/crates/router/src/consts.rs
@@ -375,6 +375,8 @@ pub mod superposition {
"should_store_eligibility_check_data_for_authentication";
/// Extended card BIN configuration key
pub const ENABLE_EXTENDED_CARD_BIN: &str = "enable_extended_card_bin";
+ /// Max auto payout retries configuration key
+ pub const MAX_AUTO_PAYOUT_RETRIES: &str = "max_auto_payout_retries";
}
#[cfg(test)]
diff --git a/crates/router/src/core/configs.rs b/crates/router/src/core/configs.rs
index c5ace10f91..b722ea3234 100644
--- a/crates/router/src/core/configs.rs
+++ b/crates/router/src/core/configs.rs
@@ -104,6 +104,18 @@ impl ConfigType for i64 {
}
}
+impl ConfigType for u32 {
+ fn from_config_str(config_str: &str) -> CustomResult<Self, errors::StorageError> {
+ config_str
+ .parse::<Self>()
+ .change_context(errors::StorageError::DeserializationFailed)
+ }
+
+ fn to_config_string(&self) -> CustomResult<String, errors::StorageError> {
+ Ok(self.to_string())
+ }
+}
+
impl ConfigType for f64 {
fn from_config_str(config_str: &str) -> CustomResult<Self, errors::StorageError> {
config_str
diff --git a/crates/router/src/core/configs/dimension_config.rs b/crates/router/src/core/configs/dimension_config.rs
index 05b55f8d53..1ada27a17b 100644
--- a/crates/router/src/core/configs/dimension_config.rs
+++ b/crates/router/src/core/configs/dimension_config.rs
@@ -262,3 +262,33 @@ impl DatabaseBackedConfig for ClientSessionValidationEnabled {
None
}
}
+
+config! {
+ superposition_key = MAX_AUTO_PAYOUT_RETRIES,
+ output = u32,
+ default = 0u32,
+ requires = dimension_state::DimensionsWithProcessorAndProviderMerchantIdAndPayoutRetryType,
+ targeting_key = id_type::CustomerId
+}
+
+impl DatabaseBackedConfig for MaxAutoPayoutRetries {
+ const KEY: &'static str = "max_auto_payout_retries";
+ fn db_key(dimensions: &impl dimension_state::DimensionsBase) -> Option<String> {
+ dimensions
+ .get_processor_merchant_id()
+ .and_then(|merchant_id| {
+ dimensions
+ .get_payout_retry_type()
+ .map(|retry_type| match retry_type {
+ common_enums::PayoutRetryType::SingleConnector => format!(
+ "max_auto_single_connector_payout_retries_enabled_{}",
+ merchant_id.get_string_repr()
+ ),
+ common_enums::PayoutRetryType::MultiConnector => format!(
+ "max_auto_multiple_connector_payout_retries_enabled_{}",
+ merchant_id.get_string_repr()
+ ),
+ })
+ })
+ }
+}
diff --git a/crates/router/src/core/configs/dimension_state.rs b/crates/router/src/core/configs/dimension_state.rs
index 9af9787af5..38c367256e 100644
--- a/crates/router/src/core/configs/dimension_state.rs
+++ b/crates/router/src/core/configs/dimension_state.rs
@@ -1,6 +1,6 @@
use std::marker::PhantomData;
-use common_enums::connector_enums::Connector;
+use common_enums::{connector_enums::Connector, PayoutRetryType};
use common_utils::id_type;
use external_services::superposition;
pub use hyperswitch_domain_models::platform::{ProcessorMerchantId, ProviderMerchantId};
@@ -59,6 +59,14 @@ pub struct NoConnector;
#[derive(Clone)]
pub struct HasConnector;
+/// Marker for state WITHOUT payout_retry_type
+#[derive(Clone)]
+pub struct NoPayoutRetryType;
+
+/// Marker for state WITH payout_retry_type
+#[derive(Clone)]
+pub struct HasPayoutRetryType;
+
// Dimensional State with type parameters
/// Dimensional state with type-level guarantees about which dimensions are present.
@@ -66,22 +74,33 @@ pub struct HasConnector;
/// Uses the type-state pattern where type parameters indicate which fields are available.
///
/// # Type Parameters
-/// * `Pm` - Provider Merchant ID type: `HasProviderMerchantId` (present) or `NoProviderMerchantId` (absent)
-/// * `M` - Processor Merchant ID type: `HasProcessorMerchantId` (present) or `NoProcessorMerchantId` (absent)
-/// * `O` - Organization ID type: `HasOrgId` (present) or `NoOrgId` (absent)
-/// * `P` - Profile ID type: `HasProfileId` (present) or `NoProfileId` (absent)
-/// * `Cn` - Connector type: `HasConnector` (present) or `NoConnector` (absent)
+/// * `Pm` - Provider Merchant ID: `HasProviderMerchantId` or `NoProviderMerchantId`
+/// * `M` - Processor Merchant ID: `HasProcessorMerchantId` or `NoProcessorMerchantId`
+/// * `O` - Organization ID: `HasOrgId` or `NoOrgId`
+/// * `P` - Profile ID: `HasProfileId` or `NoProfileId`
+/// * `Cn` - Connector: `HasConnector` or `NoConnector`
+/// * `PRT` - Payout Retry Type: `HasPayoutRetryType` or `NoPayoutRetryType`
#[derive(Clone)]
-pub struct Dimensions<Pm, M, O, P, Cn> {
+pub struct Dimensions<Pm, M, O, P, Cn, PRT> {
provider_merchant_id: Option<ProviderMerchantId>,
processor_merchant_id: Option<ProcessorMerchantId>,
organization_id: Option<id_type::OrganizationId>,
profile_id: Option<id_type::ProfileId>,
connector: Option<Connector>,
- _phantom: PhantomData<(Pm, M, O, P, Cn)>,
+ payout_retry_type: Option<PayoutRetryType>,
+ _phantom: PhantomData<(Pm, M, O, P, Cn, PRT)>,
}
-impl Dimensions<NoProviderMerchantId, NoProcessorMerchantId, NoOrgId, NoProfileId, NoConnector> {
+impl
+ Dimensions<
+ NoProviderMerchantId,
+ NoProcessorMerchantId,
+ NoOrgId,
+ NoProfileId,
+ NoConnector,
+ NoPayoutRetryType,
+ >
+{
pub fn new() -> Self {
Self {
provider_merchant_id: None,
@@ -89,165 +108,201 @@ impl Dimensions<NoProviderMerchantId, NoProcessorMerchantId, NoOrgId, NoProfileI
organization_id: None,
profile_id: None,
connector: None,
+ payout_retry_type: None,
_phantom: PhantomData,
}
}
}
/// Can only add provider_merchant_id if not already present
-impl<M, O, P, Cn> Dimensions<NoProviderMerchantId, M, O, P, Cn> {
+impl<M, O, P, Cn, PRT> Dimensions<NoProviderMerchantId, M, O, P, Cn, PRT> {
pub fn with_provider_merchant_id(
&self,
id: ProviderMerchantId,
- ) -> Dimensions<HasProviderMerchantId, M, O, P, Cn> {
+ ) -> Dimensions<HasProviderMerchantId, M, O, P, Cn, PRT> {
Dimensions {
provider_merchant_id: Some(id),
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(),
_phantom: PhantomData,
}
}
}
/// Can only add processor_merchant_id if not already present
-impl<Pm, O, P, Cn> Dimensions<Pm, NoProcessorMerchantId, O, P, Cn> {
+impl<Pm, O, P, Cn, PRT> Dimensions<Pm, NoProcessorMerchantId, O, P, Cn, PRT> {
pub fn with_processor_merchant_id(
&self,
id: ProcessorMerchantId,
- ) -> Dimensions<Pm, HasProcessorMerchantId, O, P, Cn> {
+ ) -> Dimensions<Pm, HasProcessorMerchantId, O, P, Cn, PRT> {
Dimensions {
provider_merchant_id: self.provider_merchant_id.clone(),
processor_merchant_id: Some(id),
organization_id: self.organization_id.clone(),
profile_id: self.profile_id.clone(),
connector: self.connector,
+ payout_retry_type: self.payout_retry_type.clone(),
_phantom: PhantomData,
}
}
}
/// Can only add organization_id if not already present
-impl<Pm, M, P, Cn> Dimensions<Pm, M, NoOrgId, P, Cn> {
+impl<Pm, M, P, Cn, PRT> Dimensions<Pm, M, NoOrgId, P, Cn, PRT> {
pub fn with_organization_id(
&self,
id: id_type::OrganizationId,
- ) -> Dimensions<Pm, M, HasOrgId, P, Cn> {
+ ) -> Dimensions<Pm, M, HasOrgId, P, Cn, PRT> {
Dimensions {
provider_merchant_id: self.provider_merchant_id.clone(),
processor_merchant_id: self.processor_merchant_id.clone(),
organization_id: Some(id),
profile_id: self.profile_id.clone(),
connector: self.connector,
+ payout_retry_type: self.payout_retry_type.clone(),
_phantom: PhantomData,
}
}
}
/// Can only add profile_id if not already present
-impl<Pm, M, O, Cn> Dimensions<Pm, M, O, NoProfileId, Cn> {
+impl<Pm, M, O, Cn, PRT> Dimensions<Pm, M, O, NoProfileId, Cn, PRT> {
pub fn with_profile_id(
&self,
id: id_type::ProfileId,
- ) -> Dimensions<Pm, M, O, HasProfileId, Cn> {
+ ) -> Dimensions<Pm, M, O, HasProfileId, Cn, PRT> {
Dimensions {
provider_merchant_id: self.provider_merchant_id.clone(),
processor_merchant_id: self.processor_merchant_id.clone(),
organization_id: self.organization_id.clone(),
profile_id: Some(id),
connector: self.connector,
+ payout_retry_type: self.payout_retry_type.clone(),
_phantom: PhantomData,
}
}
}
/// Can only add connector if not already present
-impl<Pm, M, O, P> Dimensions<Pm, M, O, P, NoConnector> {
- pub fn with_connector(&self, connector: Connector) -> Dimensions<Pm, M, O, P, HasConnector> {
+impl<Pm, M, O, P, PRT> Dimensions<Pm, M, O, P, NoConnector, PRT> {
+ pub fn with_connector(
+ &self,
+ connector: Connector,
+ ) -> Dimensions<Pm, M, O, P, HasConnector, PRT> {
Dimensions {
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: Some(connector),
+ payout_retry_type: self.payout_retry_type.clone(),
+ _phantom: PhantomData,
+ }
+ }
+}
+
+/// Can only add payout_retry_type if not already present
+impl<Pm, M, O, P, Cn> Dimensions<Pm, M, O, P, Cn, NoPayoutRetryType> {
+ pub fn with_payout_retry_type(
+ &self,
+ retry_type: PayoutRetryType,
+ ) -> Dimensions<Pm, M, O, P, Cn, HasPayoutRetryType> {
+ Dimensions {
+ 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: Some(retry_type),
_phantom: PhantomData,
}
}
}
/// Can only remove provider_merchant_id if currently present
-impl<M, O, P, Cn> Dimensions<HasProviderMerchantId, M, O, P, Cn> {
- pub fn without_provider_merchant_id(&self) -> Dimensions<NoProviderMerchantId, M, O, P, Cn> {
+impl<M, O, P, Cn, PRT> Dimensions<HasProviderMerchantId, M, O, P, Cn, PRT> {
+ pub fn without_provider_merchant_id(
+ &self,
+ ) -> Dimensions<NoProviderMerchantId, M, O, P, Cn, PRT> {
Dimensions {
provider_merchant_id: None,
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(),
_phantom: PhantomData,
}
}
}
/// Can only remove processor_merchant_id if currently present
-impl<Pm, O, P, Cn> Dimensions<Pm, HasProcessorMerchantId, O, P, Cn> {
- pub fn without_processor_merchant_id(&self) -> Dimensions<Pm, NoProcessorMerchantId, O, P, Cn> {
+impl<Pm, O, P, Cn, PRT> Dimensions<Pm, HasProcessorMerchantId, O, P, Cn, PRT> {
+ pub fn without_processor_merchant_id(
+ &self,
+ ) -> Dimensions<Pm, NoProcessorMerchantId, O, P, Cn, PRT> {
Dimensions {
provider_merchant_id: self.provider_merchant_id.clone(),
processor_merchant_id: None,
organization_id: self.organization_id.clone(),
profile_id: self.profile_id.clone(),
connector: self.connector,
+ payout_retry_type: self.payout_retry_type.clone(),
_phantom: PhantomData,
}
}
}
/// Can only remove organization_id if currently present
-impl<Pm, M, P, Cn> Dimensions<Pm, M, HasOrgId, P, Cn> {
- pub fn without_organization_id(&self) -> Dimensions<Pm, M, NoOrgId, P, Cn> {
+impl<Pm, M, P, Cn, PRT> Dimensions<Pm, M, HasOrgId, P, Cn, PRT> {
+ pub fn without_organization_id(&self) -> Dimensions<Pm, M, NoOrgId, P, Cn, PRT> {
Dimensions {
provider_merchant_id: self.provider_merchant_id.clone(),
processor_merchant_id: self.processor_merchant_id.clone(),
organization_id: None,
profile_id: self.profile_id.clone(),
connector: self.connector,
+ payout_retry_type: self.payout_retry_type.clone(),
_phantom: PhantomData,
}
}
}
/// Can only remove profile_id if currently present
-impl<Pm, M, O, Cn> Dimensions<Pm, M, O, HasProfileId, Cn> {
- pub fn without_profile_id(&self) -> Dimensions<Pm, M, O, NoProfileId, Cn> {
+impl<Pm, M, O, Cn, PRT> Dimensions<Pm, M, O, HasProfileId, Cn, PRT> {
+ pub fn without_profile_id(&self) -> Dimensions<Pm, M, O, NoProfileId, Cn, PRT> {
Dimensions {
provider_merchant_id: self.provider_merchant_id.clone(),
processor_merchant_id: self.processor_merchant_id.clone(),
organization_id: self.organization_id.clone(),
profile_id: None,
connector: self.connector,
+ payout_retry_type: self.payout_retry_type.clone(),
_phantom: PhantomData,
}
}
}
/// Can only remove connector if currently present
-impl<Pm, M, O, P> Dimensions<Pm, M, O, P, HasConnector> {
- pub fn without_connector(&self) -> Dimensions<Pm, M, O, P, NoConnector> {
+impl<Pm, M, O, P, PRT> Dimensions<Pm, M, O, P, HasConnector, PRT> {
+ pub fn without_connector(&self) -> Dimensions<Pm, M, O, P, NoConnector, PRT> {
Dimensions {
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: None,
+ payout_retry_type: self.payout_retry_type.clone(),
_phantom: PhantomData,
}
}
}
/// provider_merchant_id getter - only available if HasProviderMerchantId
-impl<M, O, P, Cn> Dimensions<HasProviderMerchantId, M, O, P, Cn> {
+impl<M, O, P, Cn, PRT> Dimensions<HasProviderMerchantId, M, O, P, Cn, PRT> {
pub fn provider_merchant_id(&self) -> Result<&id_type::MerchantId, DimensionError> {
self.provider_merchant_id
.as_ref()
@@ -257,7 +312,7 @@ impl<M, O, P, Cn> Dimensions<HasProviderMerchantId, M, O, P, Cn> {
}
/// processor_merchant_id getter - only available if HasProcessorMerchantId
-impl<Pm, O, P, Cn> Dimensions<Pm, HasProcessorMerchantId, O, P, Cn> {
+impl<Pm, O, P, Cn, PRT> Dimensions<Pm, HasProcessorMerchantId, O, P, Cn, PRT> {
pub fn processor_merchant_id(&self) -> Result<&id_type::MerchantId, DimensionError> {
self.processor_merchant_id
.as_ref()
@@ -267,7 +322,7 @@ impl<Pm, O, P, Cn> Dimensions<Pm, HasProcessorMerchantId, O, P, Cn> {
}
/// organization_id getter - only available if HasOrgId
-impl<Pm, M, P, Cn> Dimensions<Pm, M, HasOrgId, P, Cn> {
+impl<Pm, M, P, Cn, PRT> Dimensions<Pm, M, HasOrgId, P, Cn, PRT> {
pub fn organization_id(&self) -> Result<&id_type::OrganizationId, DimensionError> {
self.organization_id
.as_ref()
@@ -276,7 +331,7 @@ impl<Pm, M, P, Cn> Dimensions<Pm, M, HasOrgId, P, Cn> {
}
/// profile_id getter - only available if HasProfileId
-impl<Pm, M, O, Cn> Dimensions<Pm, M, O, HasProfileId, Cn> {
+impl<Pm, M, O, Cn, PRT> Dimensions<Pm, M, O, HasProfileId, Cn, PRT> {
pub fn profile_id(&self) -> Result<&id_type::ProfileId, DimensionError> {
self.profile_id
.as_ref()
@@ -285,14 +340,14 @@ impl<Pm, M, O, Cn> Dimensions<Pm, M, O, HasProfileId, Cn> {
}
/// connector getter - only available if HasConnector
-impl<Pm, M, O, P> Dimensions<Pm, M, O, P, HasConnector> {
+impl<Pm, M, O, P, PRT> Dimensions<Pm, M, O, P, HasConnector, PRT> {
pub fn connector(&self) -> Result<Connector, DimensionError> {
self.connector.ok_or(DimensionError::MissingConnector)
}
}
// Optional getters (available in any state)
-impl<Pm, M, O, P, Cn> Dimensions<Pm, M, O, P, Cn> {
+impl<Pm, M, O, P, Cn, PRT> Dimensions<Pm, M, O, P, Cn, PRT> {
pub fn get_provider_merchant_id(&self) -> Option<&id_type::MerchantId> {
self.provider_merchant_id.as_ref().map(|id| id.inner())
}
@@ -312,10 +367,14 @@ impl<Pm, M, O, P, Cn> Dimensions<Pm, M, O, P, Cn> {
pub fn get_connector(&self) -> Option<Connector> {
self.connector
}
+
+ pub fn get_payout_retry_type(&self) -> Option<&PayoutRetryType> {
+ self.payout_retry_type.as_ref()
+ }
}
// Superposition context conversion
-impl<Pm, M, O, P, Cn> Dimensions<Pm, M, O, P, Cn> {
+impl<Pm, M, O, P, Cn, PRT> Dimensions<Pm, M, O, P, Cn, PRT> {
/// Converts dimension state to Superposition config context
pub fn to_superposition_context(&self) -> Option<superposition::ConfigContext> {
let mut ctx = superposition::ConfigContext::new();
@@ -340,12 +399,23 @@ impl<Pm, M, O, P, Cn> Dimensions<Pm, M, O, P, Cn> {
ctx = ctx.with("connector", conn.to_string().as_str());
}
+ if let Some(ref prt) = self.payout_retry_type {
+ ctx = ctx.with("payout_retry_type", prt.to_string().as_str());
+ }
+
Some(ctx)
}
}
impl Default
- for Dimensions<NoProviderMerchantId, NoProcessorMerchantId, NoOrgId, NoProfileId, NoConnector>
+ for Dimensions<
+ NoProviderMerchantId,
+ NoProcessorMerchantId,
+ NoOrgId,
+ NoProfileId,
+ NoConnector,
+ NoPayoutRetryType,
+ >
{
fn default() -> Self {
Self::new()
@@ -371,9 +441,12 @@ pub trait DimensionsBase {
/// Get connector (if available)
fn get_connector(&self) -> Option<Connector>;
+
+ /// Get payout_retry_type (if available)
+ fn get_payout_retry_type(&self) -> Option<&PayoutRetryType>;
}
-impl<Pm, M, O, P, Cn> DimensionsBase for Dimensions<Pm, M, O, P, Cn> {
+impl<Pm, M, O, P, Cn, PRT> DimensionsBase for Dimensions<Pm, M, O, P, Cn, PRT> {
fn to_superposition_context(&self) -> Option<superposition::ConfigContext> {
self.to_superposition_context()
}
@@ -397,18 +470,66 @@ impl<Pm, M, O, P, Cn> DimensionsBase for Dimensions<Pm, M, O, P, Cn> {
fn get_connector(&self) -> Option<Connector> {
self.get_connector()
}
+
+ fn get_payout_retry_type(&self) -> Option<&PayoutRetryType> {
+ self.get_payout_retry_type()
+ }
}
// Type aliases - both provider and processor merchant IDs present
-pub type DimensionsWithProcessorAndProviderMerchantId =
- Dimensions<HasProviderMerchantId, HasProcessorMerchantId, NoOrgId, NoProfileId, NoConnector>;
-pub type DimensionsWithProcessorAndProviderMerchantIdAndProfileId =
- Dimensions<HasProviderMerchantId, HasProcessorMerchantId, NoOrgId, HasProfileId, NoConnector>;
-pub type DimensionsWithProcessorAndProviderMerchantIdAndConnector =
- Dimensions<HasProviderMerchantId, HasProcessorMerchantId, NoOrgId, NoProfileId, HasConnector>;
-pub type DimensionsWithProcessorAndProviderMerchantIdAndProfileIdAndConnector =
- Dimensions<HasProviderMerchantId, HasProcessorMerchantId, NoOrgId, HasProfileId, HasConnector>;
-pub type DimensionsWithProcessorAndProviderMerchantIdAndOrgId =
- Dimensions<HasProviderMerchantId, HasProcessorMerchantId, HasOrgId, NoProfileId, NoConnector>;
-pub type DimensionsWithProcessorAndProviderMerchantIdAndOrgIdAndProfileId =
- Dimensions<HasProviderMerchantId, HasProcessorMerchantId, HasOrgId, HasProfileId, NoConnector>;
+pub type DimensionsWithProcessorAndProviderMerchantId = Dimensions<
+ HasProviderMerchantId,
+ HasProcessorMerchantId,
+ NoOrgId,
+ NoProfileId,
+ NoConnector,
+ NoPayoutRetryType,
+>;
+pub type DimensionsWithProcessorAndProviderMerchantIdAndProfileId = Dimensions<
+ HasProviderMerchantId,
+ HasProcessorMerchantId,
+ NoOrgId,
+ HasProfileId,
+ NoConnector,
+ NoPayoutRetryType,
+>;
+pub type DimensionsWithProcessorAndProviderMerchantIdAndConnector = Dimensions<
+ HasProviderMerchantId,
+ HasProcessorMerchantId,
+ NoOrgId,
+ NoProfileId,
+ HasConnector,
+ NoPayoutRetryType,
+>;
+pub type DimensionsWithProcessorAndProviderMerchantIdAndProfileIdAndConnector = Dimensions<
+ HasProviderMerchantId,
+ HasProcessorMerchantId,
+ NoOrgId,
+ HasProfileId,
+ HasConnector,
+ NoPayoutRetryType,
+>;
+pub type DimensionsWithProcessorAndProviderMerchantIdAndOrgId = Dimensions<
+ HasProviderMerchantId,
+ HasProcessorMerchantId,
+ HasOrgId,
+ NoProfileId,
+ NoConnector,
+ NoPayoutRetryType,
+>;
+pub type DimensionsWithProcessorAndProviderMerchantIdAndOrgIdAndProfileId = Dimensions<
+ HasProviderMerchantId,
+ HasProcessorMerchantId,
+ HasOrgId,
+ HasProfileId,
+ NoConnector,
+ NoPayoutRetryType,
+>;
+pub type DimensionsWithProcessorAndProviderMerchantIdAndPayoutRetryType = Dimensions<
+ HasProviderMerchantId,
+ HasProcessorMerchantId,
+ NoOrgId,
+ NoProfileId,
+ NoConnector,
+ HasPayoutRetryType,
+>;
diff --git a/crates/router/src/core/payouts/retry.rs b/crates/router/src/core/payouts/retry.rs
index 12083e974e..2f393dd854 100644
--- a/crates/router/src/core/payouts/retry.rs
+++ b/crates/router/src/core/payouts/retry.rs
@@ -47,7 +47,8 @@ pub async fn do_gsm_multiple_connector_actions(
retries = get_retries(
state,
retries,
- platform.get_processor().get_account().get_id(),
+ dimensions,
+ payout_data.payout_attempt.customer_id.as_ref(),
PayoutRetryType::MultiConnector,
)
.await;
@@ -76,7 +77,7 @@ pub async fn do_gsm_multiple_connector_actions(
))
.await?;
- retries = retries.map(|i| i - 1);
+ retries = retries.map(|i| i.saturating_sub(1));
}
common_enums::GsmDecision::DoDefault => break,
}
@@ -114,7 +115,8 @@ pub async fn do_gsm_single_connector_actions(
retries = get_retries(
state,
retries,
- platform.get_processor().get_account().get_id(),
+ dimensions,
+ payout_data.payout_attempt.customer_id.as_ref(),
PayoutRetryType::SingleConnector,
)
.await;
@@ -135,7 +137,7 @@ pub async fn do_gsm_single_connector_actions(
))
.await?;
- retries = retries.map(|i| i - 1);
+ retries = retries.map(|i| i.saturating_sub(1));
}
common_enums::GsmDecision::DoDefault => break,
}
@@ -146,30 +148,24 @@ pub async fn do_gsm_single_connector_actions(
#[instrument(skip_all)]
pub async fn get_retries(
state: &app::SessionState,
- retries: Option<i32>,
- merchant_id: &common_utils::id_type::MerchantId,
+ retries: Option<u32>,
+ dimensions: &dimension_state::DimensionsWithProcessorAndProviderMerchantId,
+ customer_id: Option<&common_utils::id_type::CustomerId>,
retry_type: PayoutRetryType,
-) -> Option<i32> {
+) -> Option<u32> {
match retries {
Some(retries) => Some(retries),
None => {
- let key = merchant_id.get_max_auto_single_connector_payout_retries_enabled(retry_type);
- let db = &*state.store;
- db.find_config_by_key(key.as_str())
- .await
- .change_context(errors::ApiErrorResponse::InternalServerError)
- .and_then(|retries_config| {
- retries_config
- .config
- .parse::<i32>()
- .change_context(errors::ApiErrorResponse::InternalServerError)
- .attach_printable("Retries config parsing failed")
- })
- .map_err(|err| {
- logger::error!(retries_error=?err);
- None::<i32>
- })
- .ok()
+ let storage = state.store.as_ref();
+ let superposition_client = state.superposition_service.as_ref();
+
+ let dimensions = dimensions.with_payout_retry_type(retry_type);
+
+ let retries = dimensions
+ .get_max_auto_payout_retries(storage, superposition_client, customer_id)
+ .await;
+
+ Some(retries)
}
}
}