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(router): add auto retries configs in profile CRUD apis (#6134)

Sai Harsha Vardhanbf47b560c2cb
diff --git a/api-reference/openapi_spec.json b/api-reference/openapi_spec.json
index 4d8d523923..d91dbb9f82 100644
--- a/api-reference/openapi_spec.json
+++ b/api-reference/openapi_spec.json
@@ -21220,6 +21220,18 @@
"is_network_tokenization_enabled": {
"type": "boolean",
"description": "Indicates if is_network_tokenization_enabled is enabled or not.\nIf set to `true` is_network_tokenization_enabled will be checked."
+ },
+ "is_auto_retries_enabled": {
+ "type": "boolean",
+ "description": "Indicates if is_auto_retries_enabled is enabled or not.",
+ "nullable": true
+ },
+ "max_auto_retries_enabled": {
+ "type": "integer",
+ "format": "int32",
+ "description": "Maximum number of auto retries allowed for a payment",
+ "nullable": true,
+ "minimum": 0
}
},
"additionalProperties": false
@@ -21251,7 +21263,8 @@
"enable_payment_response_hash",
"redirect_to_merchant_with_http_post",
"is_tax_connector_enabled",
- "is_network_tokenization_enabled"
+ "is_network_tokenization_enabled",
+ "is_auto_retries_enabled"
],
"properties": {
"merchant_id": {
@@ -21436,6 +21449,18 @@
"description": "Indicates if is_network_tokenization_enabled is enabled or not.\nIf set to `true` is_network_tokenization_enabled will be checked.",
"default": false,
"example": false
+ },
+ "is_auto_retries_enabled": {
+ "type": "boolean",
+ "description": "Indicates if is_auto_retries_enabled is enabled or not.",
+ "default": false,
+ "example": false
+ },
+ "max_auto_retries_enabled": {
+ "type": "integer",
+ "format": "int32",
+ "description": "Maximum number of auto retries allowed for a payment",
+ "nullable": true
}
}
},
diff --git a/crates/api_models/src/admin.rs b/crates/api_models/src/admin.rs
index 6f65633956..6e7f4f29d0 100644
--- a/crates/api_models/src/admin.rs
+++ b/crates/api_models/src/admin.rs
@@ -1971,6 +1971,12 @@ pub struct ProfileCreate {
/// If set to `true` is_network_tokenization_enabled will be checked.
#[serde(default)]
pub is_network_tokenization_enabled: bool,
+
+ /// Indicates if is_auto_retries_enabled is enabled or not.
+ pub is_auto_retries_enabled: Option<bool>,
+
+ /// Maximum number of auto retries allowed for a payment
+ pub max_auto_retries_enabled: Option<u8>,
}
#[nutype::nutype(
@@ -2202,6 +2208,13 @@ pub struct ProfileResponse {
/// If set to `true` is_network_tokenization_enabled will be checked.
#[schema(default = false, example = false)]
pub is_network_tokenization_enabled: bool,
+
+ /// Indicates if is_auto_retries_enabled is enabled or not.
+ #[schema(default = false, example = false)]
+ pub is_auto_retries_enabled: bool,
+
+ /// Maximum number of auto retries allowed for a payment
+ pub max_auto_retries_enabled: Option<i16>,
}
#[cfg(feature = "v2")]
@@ -2431,6 +2444,12 @@ pub struct ProfileUpdate {
/// Indicates if is_network_tokenization_enabled is enabled or not.
pub is_network_tokenization_enabled: Option<bool>,
+
+ /// Indicates if is_auto_retries_enabled is enabled or not.
+ pub is_auto_retries_enabled: Option<bool>,
+
+ /// Maximum number of auto retries allowed for a payment
+ pub max_auto_retries_enabled: Option<u8>,
}
#[cfg(feature = "v2")]
diff --git a/crates/diesel_models/src/business_profile.rs b/crates/diesel_models/src/business_profile.rs
index 4edc2ba243..fd0abc1661 100644
--- a/crates/diesel_models/src/business_profile.rs
+++ b/crates/diesel_models/src/business_profile.rs
@@ -55,6 +55,8 @@ pub struct Profile {
pub version: common_enums::ApiVersion,
pub dynamic_routing_algorithm: Option<serde_json::Value>,
pub is_network_tokenization_enabled: bool,
+ pub is_auto_retries_enabled: Option<bool>,
+ pub max_auto_retries_enabled: Option<i16>,
}
#[cfg(feature = "v1")]
@@ -96,6 +98,8 @@ pub struct ProfileNew {
pub is_tax_connector_enabled: Option<bool>,
pub version: common_enums::ApiVersion,
pub is_network_tokenization_enabled: bool,
+ pub is_auto_retries_enabled: Option<bool>,
+ pub max_auto_retries_enabled: Option<i16>,
}
#[cfg(feature = "v1")]
@@ -134,6 +138,8 @@ pub struct ProfileUpdateInternal {
pub is_tax_connector_enabled: Option<bool>,
pub dynamic_routing_algorithm: Option<serde_json::Value>,
pub is_network_tokenization_enabled: Option<bool>,
+ pub is_auto_retries_enabled: Option<bool>,
+ pub max_auto_retries_enabled: Option<i16>,
}
#[cfg(feature = "v1")]
@@ -171,6 +177,8 @@ impl ProfileUpdateInternal {
is_tax_connector_enabled,
dynamic_routing_algorithm,
is_network_tokenization_enabled,
+ is_auto_retries_enabled,
+ max_auto_retries_enabled,
} = self;
Profile {
profile_id: source.profile_id,
@@ -228,6 +236,8 @@ impl ProfileUpdateInternal {
.or(source.dynamic_routing_algorithm),
is_network_tokenization_enabled: is_network_tokenization_enabled
.unwrap_or(source.is_network_tokenization_enabled),
+ is_auto_retries_enabled: is_auto_retries_enabled.or(source.is_auto_retries_enabled),
+ max_auto_retries_enabled: max_auto_retries_enabled.or(source.max_auto_retries_enabled),
}
}
}
@@ -279,6 +289,8 @@ pub struct Profile {
pub version: common_enums::ApiVersion,
pub dynamic_routing_algorithm: Option<serde_json::Value>,
pub is_network_tokenization_enabled: bool,
+ pub is_auto_retries_enabled: Option<bool>,
+ pub max_auto_retries_enabled: Option<i16>,
}
impl Profile {
@@ -334,6 +346,8 @@ pub struct ProfileNew {
pub id: common_utils::id_type::ProfileId,
pub version: common_enums::ApiVersion,
pub is_network_tokenization_enabled: bool,
+ pub is_auto_retries_enabled: Option<bool>,
+ pub max_auto_retries_enabled: Option<i16>,
}
#[cfg(feature = "v2")]
@@ -373,6 +387,8 @@ pub struct ProfileUpdateInternal {
pub payout_routing_algorithm_id: Option<common_utils::id_type::RoutingId>,
pub default_fallback_routing: Option<pii::SecretSerdeValue>,
pub is_network_tokenization_enabled: Option<bool>,
+ pub is_auto_retries_enabled: Option<bool>,
+ pub max_auto_retries_enabled: Option<i16>,
}
#[cfg(feature = "v2")]
@@ -411,6 +427,8 @@ impl ProfileUpdateInternal {
payout_routing_algorithm_id,
default_fallback_routing,
is_network_tokenization_enabled,
+ is_auto_retries_enabled,
+ max_auto_retries_enabled,
} = self;
Profile {
id: source.id,
@@ -471,6 +489,8 @@ impl ProfileUpdateInternal {
dynamic_routing_algorithm: None,
is_network_tokenization_enabled: is_network_tokenization_enabled
.unwrap_or(source.is_network_tokenization_enabled),
+ is_auto_retries_enabled: is_auto_retries_enabled.or(source.is_auto_retries_enabled),
+ max_auto_retries_enabled: max_auto_retries_enabled.or(source.max_auto_retries_enabled),
}
}
}
diff --git a/crates/diesel_models/src/schema.rs b/crates/diesel_models/src/schema.rs
index 77140891ad..a9e0b54260 100644
--- a/crates/diesel_models/src/schema.rs
+++ b/crates/diesel_models/src/schema.rs
@@ -211,6 +211,8 @@ diesel::table! {
version -> ApiVersion,
dynamic_routing_algorithm -> Nullable<Json>,
is_network_tokenization_enabled -> Bool,
+ is_auto_retries_enabled -> Nullable<Bool>,
+ max_auto_retries_enabled -> Nullable<Int2>,
}
}
diff --git a/crates/diesel_models/src/schema_v2.rs b/crates/diesel_models/src/schema_v2.rs
index 1c81b402f7..53f568f18c 100644
--- a/crates/diesel_models/src/schema_v2.rs
+++ b/crates/diesel_models/src/schema_v2.rs
@@ -218,6 +218,8 @@ diesel::table! {
version -> ApiVersion,
dynamic_routing_algorithm -> Nullable<Json>,
is_network_tokenization_enabled -> Bool,
+ is_auto_retries_enabled -> Nullable<Bool>,
+ max_auto_retries_enabled -> Nullable<Int2>,
}
}
diff --git a/crates/hyperswitch_domain_models/src/business_profile.rs b/crates/hyperswitch_domain_models/src/business_profile.rs
index 156ca4d2fe..75cdd40024 100644
--- a/crates/hyperswitch_domain_models/src/business_profile.rs
+++ b/crates/hyperswitch_domain_models/src/business_profile.rs
@@ -56,6 +56,8 @@ pub struct Profile {
pub version: common_enums::ApiVersion,
pub dynamic_routing_algorithm: Option<serde_json::Value>,
pub is_network_tokenization_enabled: bool,
+ pub is_auto_retries_enabled: bool,
+ pub max_auto_retries_enabled: Option<i16>,
}
#[cfg(feature = "v1")]
@@ -94,6 +96,8 @@ pub struct ProfileSetter {
pub is_tax_connector_enabled: bool,
pub dynamic_routing_algorithm: Option<serde_json::Value>,
pub is_network_tokenization_enabled: bool,
+ pub is_auto_retries_enabled: bool,
+ pub max_auto_retries_enabled: Option<i16>,
}
#[cfg(feature = "v1")]
@@ -139,6 +143,8 @@ impl From<ProfileSetter> for Profile {
version: consts::API_VERSION,
dynamic_routing_algorithm: value.dynamic_routing_algorithm,
is_network_tokenization_enabled: value.is_network_tokenization_enabled,
+ is_auto_retries_enabled: value.is_auto_retries_enabled,
+ max_auto_retries_enabled: value.max_auto_retries_enabled,
}
}
}
@@ -186,6 +192,8 @@ pub struct ProfileGeneralUpdate {
pub is_tax_connector_enabled: Option<bool>,
pub dynamic_routing_algorithm: Option<serde_json::Value>,
pub is_network_tokenization_enabled: Option<bool>,
+ pub is_auto_retries_enabled: Option<bool>,
+ pub max_auto_retries_enabled: Option<i16>,
}
#[cfg(feature = "v1")]
@@ -246,6 +254,8 @@ impl From<ProfileUpdate> for ProfileUpdateInternal {
is_tax_connector_enabled,
dynamic_routing_algorithm,
is_network_tokenization_enabled,
+ is_auto_retries_enabled,
+ max_auto_retries_enabled,
} = *update;
Self {
@@ -281,6 +291,8 @@ impl From<ProfileUpdate> for ProfileUpdateInternal {
is_tax_connector_enabled,
dynamic_routing_algorithm,
is_network_tokenization_enabled,
+ is_auto_retries_enabled,
+ max_auto_retries_enabled,
}
}
ProfileUpdate::RoutingAlgorithmUpdate {
@@ -318,6 +330,8 @@ impl From<ProfileUpdate> for ProfileUpdateInternal {
is_tax_connector_enabled: None,
dynamic_routing_algorithm: None,
is_network_tokenization_enabled: None,
+ is_auto_retries_enabled: None,
+ max_auto_retries_enabled: None,
},
ProfileUpdate::DynamicRoutingAlgorithmUpdate {
dynamic_routing_algorithm,
@@ -353,6 +367,8 @@ impl From<ProfileUpdate> for ProfileUpdateInternal {
is_tax_connector_enabled: None,
dynamic_routing_algorithm,
is_network_tokenization_enabled: None,
+ is_auto_retries_enabled: None,
+ max_auto_retries_enabled: None,
},
ProfileUpdate::ExtendedCardInfoUpdate {
is_extended_card_info_enabled,
@@ -388,6 +404,8 @@ impl From<ProfileUpdate> for ProfileUpdateInternal {
is_tax_connector_enabled: None,
dynamic_routing_algorithm: None,
is_network_tokenization_enabled: None,
+ is_auto_retries_enabled: None,
+ max_auto_retries_enabled: None,
},
ProfileUpdate::ConnectorAgnosticMitUpdate {
is_connector_agnostic_mit_enabled,
@@ -423,6 +441,8 @@ impl From<ProfileUpdate> for ProfileUpdateInternal {
is_tax_connector_enabled: None,
dynamic_routing_algorithm: None,
is_network_tokenization_enabled: None,
+ is_auto_retries_enabled: None,
+ max_auto_retries_enabled: None,
},
ProfileUpdate::NetworkTokenizationUpdate {
is_network_tokenization_enabled,
@@ -458,6 +478,8 @@ impl From<ProfileUpdate> for ProfileUpdateInternal {
is_tax_connector_enabled: None,
dynamic_routing_algorithm: None,
is_network_tokenization_enabled,
+ is_auto_retries_enabled: None,
+ max_auto_retries_enabled: None,
},
}
}
@@ -512,6 +534,8 @@ impl super::behaviour::Conversion for Profile {
version: self.version,
dynamic_routing_algorithm: self.dynamic_routing_algorithm,
is_network_tokenization_enabled: self.is_network_tokenization_enabled,
+ is_auto_retries_enabled: Some(self.is_auto_retries_enabled),
+ max_auto_retries_enabled: self.max_auto_retries_enabled,
})
}
@@ -578,6 +602,8 @@ impl super::behaviour::Conversion for Profile {
version: item.version,
dynamic_routing_algorithm: item.dynamic_routing_algorithm,
is_network_tokenization_enabled: item.is_network_tokenization_enabled,
+ is_auto_retries_enabled: item.is_auto_retries_enabled.unwrap_or(false),
+ max_auto_retries_enabled: item.max_auto_retries_enabled,
})
}
.await
@@ -628,6 +654,8 @@ impl super::behaviour::Conversion for Profile {
is_tax_connector_enabled: Some(self.is_tax_connector_enabled),
version: self.version,
is_network_tokenization_enabled: self.is_network_tokenization_enabled,
+ is_auto_retries_enabled: Some(self.is_auto_retries_enabled),
+ max_auto_retries_enabled: self.max_auto_retries_enabled,
})
}
}
@@ -896,6 +924,8 @@ impl From<ProfileUpdate> for ProfileUpdateInternal {
tax_connector_id: None,
is_tax_connector_enabled: None,
is_network_tokenization_enabled,
+ is_auto_retries_enabled: None,
+ max_auto_retries_enabled: None,
}
}
ProfileUpdate::RoutingAlgorithmUpdate {
@@ -934,6 +964,8 @@ impl From<ProfileUpdate> for ProfileUpdateInternal {
tax_connector_id: None,
is_tax_connector_enabled: None,
is_network_tokenization_enabled: None,
+ is_auto_retries_enabled: None,
+ max_auto_retries_enabled: None,
},
ProfileUpdate::ExtendedCardInfoUpdate {
is_extended_card_info_enabled,
@@ -970,6 +1002,8 @@ impl From<ProfileUpdate> for ProfileUpdateInternal {
tax_connector_id: None,
is_tax_connector_enabled: None,
is_network_tokenization_enabled: None,
+ is_auto_retries_enabled: None,
+ max_auto_retries_enabled: None,
},
ProfileUpdate::ConnectorAgnosticMitUpdate {
is_connector_agnostic_mit_enabled,
@@ -1006,6 +1040,8 @@ impl From<ProfileUpdate> for ProfileUpdateInternal {
tax_connector_id: None,
is_tax_connector_enabled: None,
is_network_tokenization_enabled: None,
+ is_auto_retries_enabled: None,
+ max_auto_retries_enabled: None,
},
ProfileUpdate::DefaultRoutingFallbackUpdate {
default_fallback_routing,
@@ -1042,6 +1078,8 @@ impl From<ProfileUpdate> for ProfileUpdateInternal {
tax_connector_id: None,
is_tax_connector_enabled: None,
is_network_tokenization_enabled: None,
+ is_auto_retries_enabled: None,
+ max_auto_retries_enabled: None,
},
ProfileUpdate::NetworkTokenizationUpdate {
is_network_tokenization_enabled,
@@ -1078,6 +1116,8 @@ impl From<ProfileUpdate> for ProfileUpdateInternal {
tax_connector_id: None,
is_tax_connector_enabled: None,
is_network_tokenization_enabled,
+ is_auto_retries_enabled: None,
+ max_auto_retries_enabled: None,
},
}
}
@@ -1134,6 +1174,8 @@ impl super::behaviour::Conversion for Profile {
version: self.version,
dynamic_routing_algorithm: None,
is_network_tokenization_enabled: self.is_network_tokenization_enabled,
+ is_auto_retries_enabled: None,
+ max_auto_retries_enabled: None,
})
}
@@ -1253,6 +1295,8 @@ impl super::behaviour::Conversion for Profile {
is_tax_connector_enabled: Some(self.is_tax_connector_enabled),
version: self.version,
is_network_tokenization_enabled: self.is_network_tokenization_enabled,
+ is_auto_retries_enabled: None,
+ max_auto_retries_enabled: None,
})
}
}
diff --git a/crates/router/src/core/admin.rs b/crates/router/src/core/admin.rs
index ad9925a241..d27b6b82fd 100644
--- a/crates/router/src/core/admin.rs
+++ b/crates/router/src/core/admin.rs
@@ -3537,6 +3537,8 @@ impl ProfileCreateBridge for api::ProfileCreate {
.always_collect_shipping_details_from_wallet_connector,
dynamic_routing_algorithm: None,
is_network_tokenization_enabled: self.is_network_tokenization_enabled,
+ is_auto_retries_enabled: self.is_auto_retries_enabled.unwrap_or_default(),
+ max_auto_retries_enabled: self.max_auto_retries_enabled.map(i16::from),
}))
}
@@ -3884,6 +3886,8 @@ impl ProfileUpdateBridge for api::ProfileUpdate {
is_tax_connector_enabled: self.is_tax_connector_enabled,
dynamic_routing_algorithm: self.dynamic_routing_algorithm,
is_network_tokenization_enabled: self.is_network_tokenization_enabled,
+ is_auto_retries_enabled: self.is_auto_retries_enabled,
+ max_auto_retries_enabled: self.max_auto_retries_enabled.map(i16::from),
},
)))
}
diff --git a/crates/router/src/types/api/admin.rs b/crates/router/src/types/api/admin.rs
index c7b76d1780..8d52e5dc11 100644
--- a/crates/router/src/types/api/admin.rs
+++ b/crates/router/src/types/api/admin.rs
@@ -168,6 +168,8 @@ impl ForeignTryFrom<domain::Profile> for ProfileResponse {
tax_connector_id: item.tax_connector_id,
is_tax_connector_enabled: item.is_tax_connector_enabled,
is_network_tokenization_enabled: item.is_network_tokenization_enabled,
+ is_auto_retries_enabled: item.is_auto_retries_enabled,
+ max_auto_retries_enabled: item.max_auto_retries_enabled,
})
}
}
@@ -353,5 +355,7 @@ pub async fn create_profile_from_merchant_account(
is_tax_connector_enabled: request.is_tax_connector_enabled,
dynamic_routing_algorithm: None,
is_network_tokenization_enabled: request.is_network_tokenization_enabled,
+ is_auto_retries_enabled: request.is_auto_retries_enabled.unwrap_or_default(),
+ max_auto_retries_enabled: request.max_auto_retries_enabled.map(i16::from),
}))
}
diff --git a/migrations/2024-09-26-113912_add-auto-retries-configs-in-profile/down.sql b/migrations/2024-09-26-113912_add-auto-retries-configs-in-profile/down.sql
new file mode 100644
index 0000000000..3751f25da4
--- /dev/null
+++ b/migrations/2024-09-26-113912_add-auto-retries-configs-in-profile/down.sql
@@ -0,0 +1,6 @@
+-- This file should undo anything in `up.sql`
+-- Drop is_auto_retries_enabled column from business_profile table
+ALTER TABLE business_profile DROP COLUMN IF EXISTS is_auto_retries_enabled;
+
+-- Drop max_auto_retries_enabled column from business_profile table
+ALTER TABLE business_profile DROP COLUMN IF EXISTS max_auto_retries_enabled;
diff --git a/migrations/2024-09-26-113912_add-auto-retries-configs-in-profile/up.sql b/migrations/2024-09-26-113912_add-auto-retries-configs-in-profile/up.sql
new file mode 100644
index 0000000000..05b6a114a3
--- /dev/null
+++ b/migrations/2024-09-26-113912_add-auto-retries-configs-in-profile/up.sql
@@ -0,0 +1,6 @@
+-- Your SQL goes here
+-- Add is_auto_retries_enabled column in business_profile table
+ALTER TABLE business_profile ADD COLUMN IF NOT EXISTS is_auto_retries_enabled BOOLEAN;
+
+-- Add max_auto_retries_enabled column in business_profile table
+ALTER TABLE business_profile ADD COLUMN IF NOT EXISTS max_auto_retries_enabled SMALLINT;