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
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
feat(revenue_recovery): add trigger model setting to the v2 profile (#15148)
CHALLA NISHANTH BABU90bde494da77
diff --git a/api-reference/v2/openapi_spec_v2.json b/api-reference/v2/openapi_spec_v2.jsonindex 00e91dd5f8..410bf8c767 100644--- a/api-reference/v2/openapi_spec_v2.json+++ b/api-reference/v2/openapi_spec_v2.json@@ -30569,6 +30569,15 @@"default": "skip","nullable": true},+ "revenue_recovery_trigger_model": {+ "allOf": [+ {+ "$ref": "#/components/schemas/RevenueRecoveryTriggerModel"+ }+ ],+ "default": "internal_triggers",+ "nullable": true+ },"billing_processor_id": {"type": "string","description": "Merchant Connector id to be stored for billing_processor connector",@@ -30632,7 +30641,8 @@"is_network_tokenization_enabled","is_click_to_pay_enabled","is_clear_pan_retries_enabled",- "split_txns_enabled"+ "split_txns_enabled",+ "revenue_recovery_trigger_model"],"properties": {"merchant_id": {@@ -30893,6 +30903,14 @@],"default": "skip"},+ "revenue_recovery_trigger_model": {+ "allOf": [+ {+ "$ref": "#/components/schemas/RevenueRecoveryTriggerModel"+ }+ ],+ "default": "internal_triggers"+ },"revenue_recovery_retry_algorithm_type": {"allOf": [{@@ -33120,6 +33138,14 @@}}},+ "RevenueRecoveryTriggerModel": {+ "type": "string",+ "description": "Decides who triggers the retries of a failed invoice under revenue recovery, and so which\nmodel the recovery API follows.",+ "enum": [+ "internal_triggers",+ "external_triggers"+ ]+ },"RevokeApiKeyResponse": {"type": "object","description": "The response body for revoking an API Key.",diff --git a/crates/api_models/src/admin.rs b/crates/api_models/src/admin.rsindex dc39052796..7faea65804 100644--- a/crates/api_models/src/admin.rs+++ b/crates/api_models/src/admin.rs@@ -2814,6 +2814,10 @@ pub struct ProfileCreate {#[schema(value_type = Option<SplitTxnsEnabled>, default = "skip")]pub split_txns_enabled: Option<common_enums::SplitTxnsEnabled>,+ /// Decides who triggers the retries of failed invoices under revenue recovery, and so which fields the recovery API needs. With `internal_triggers` Hyperswitch schedules the retries using the billing and payment merchant connector accounts. With `external_triggers` the merchant triggers them, and transactions are only recorded, without any merchant connector account.+ #[schema(value_type = Option<RevenueRecoveryTriggerModel>, default = "internal_triggers", example = "external_triggers")]+ pub revenue_recovery_trigger_model: Option<common_enums::RevenueRecoveryTriggerModel>,+/// Merchant Connector id to be stored for billing_processor connector#[schema(value_type = Option<String>)]pub billing_processor_id: Option<id_type::MerchantConnectorAccountId>,@@ -3221,6 +3225,10 @@ pub struct ProfileResponse {#[schema(value_type = SplitTxnsEnabled, default = "skip")]pub split_txns_enabled: common_enums::SplitTxnsEnabled,+ /// Decides who triggers the retries of failed invoices under revenue recovery, and so which fields the recovery API needs. With `internal_triggers` Hyperswitch schedules the retries using the billing and payment merchant connector accounts. With `external_triggers` the merchant triggers them, and transactions are only recorded, without any merchant connector account.+ #[schema(value_type = RevenueRecoveryTriggerModel, default = "internal_triggers", example = "external_triggers")]+ pub revenue_recovery_trigger_model: common_enums::RevenueRecoveryTriggerModel,+/// Indicates the state of revenue recovery algorithm type#[schema(value_type = Option<RevenueRecoveryAlgorithmType>, example = "cascading")]pub revenue_recovery_retry_algorithm_type:@@ -3605,6 +3613,10 @@ pub struct ProfileUpdate {#[schema(value_type = Option<SplitTxnsEnabled>, default = "skip")]pub split_txns_enabled: Option<common_enums::SplitTxnsEnabled>,+ /// Decides who triggers the retries of failed invoices under revenue recovery, and so which fields the recovery API needs. With `internal_triggers` Hyperswitch schedules the retries using the billing and payment merchant connector accounts. With `external_triggers` the merchant triggers them, and transactions are only recorded, without any merchant connector account.+ #[schema(value_type = Option<RevenueRecoveryTriggerModel>, default = "internal_triggers", example = "external_triggers")]+ pub revenue_recovery_trigger_model: Option<common_enums::RevenueRecoveryTriggerModel>,+/// Merchant Connector id to be stored for billing_processor connector#[schema(value_type = Option<String>)]pub billing_processor_id: Option<id_type::MerchantConnectorAccountId>,diff --git a/crates/common_enums/src/enums.rs b/crates/common_enums/src/enums.rsindex ade619ece1..90d35c9a1b 100644--- a/crates/common_enums/src/enums.rs+++ b/crates/common_enums/src/enums.rs@@ -387,6 +387,36 @@ pub enum RevenueRecoveryAlgorithmType {Cascading,}+/// Decides who triggers the retries of a failed invoice under revenue recovery, and so which+/// model the recovery API follows.+#[derive(+ Clone,+ Copy,+ Debug,+ Default,+ Eq,+ Hash,+ PartialEq,+ serde::Deserialize,+ serde::Serialize,+ strum::Display,+ strum::EnumString,+ ToSchema,+)]+#[cfg_attr(feature = "diesel", router_derive::diesel_enum(storage_type = "text"))]+#[serde(rename_all = "snake_case")]+#[strum(serialize_all = "snake_case")]+pub enum RevenueRecoveryTriggerModel {+ /// Hyperswitch triggers the retries through the billing and payment merchant connector+ /// accounts the transactions are recorded against.+ #[default]+ InternalTriggers,+ /// The merchant triggers the retries and reports their results. Transactions are recorded+ /// without any merchant connector account, and the retry limits come from the+ /// `revenue_recovery_config` of the profile, which this model requires.+ ExternalTriggers,+}+/// The retry implementations available within the `Smart` arm of revenue recovery.#[derive(Clone,diff --git a/crates/diesel_models/src/business_profile.rs b/crates/diesel_models/src/business_profile.rsindex 8633a59f65..29500bb376 100644--- a/crates/diesel_models/src/business_profile.rs+++ b/crates/diesel_models/src/business_profile.rs@@ -338,6 +338,7 @@ pub struct Profile {pub revenue_recovery_retry_algorithm_data: Option<RevenueRecoveryAlgorithmData>,pub split_txns_enabled: Option<common_enums::SplitTxnsEnabled>,pub revenue_recovery_config: Option<RevenueRecoveryConfig>,+ pub revenue_recovery_trigger_model: Option<common_enums::RevenueRecoveryTriggerModel>,}impl Profile {@@ -417,6 +418,7 @@ pub struct ProfileNew {pub external_vault_connector_details: Option<ExternalVaultConnectorDetails>,pub is_l2_l3_enabled: Option<bool>,pub split_txns_enabled: Option<common_enums::SplitTxnsEnabled>,+ pub revenue_recovery_trigger_model: Option<common_enums::RevenueRecoveryTriggerModel>,pub payment_method_blocking: Option<PaymentMethodBlockingConfig>,pub revenue_recovery_config: Option<RevenueRecoveryConfig>,}@@ -483,6 +485,7 @@ pub struct ProfileUpdateInternal {pub external_vault_connector_details: Option<ExternalVaultConnectorDetails>,pub is_l2_l3_enabled: Option<bool>,pub split_txns_enabled: Option<common_enums::SplitTxnsEnabled>,+ pub revenue_recovery_trigger_model: Option<common_enums::RevenueRecoveryTriggerModel>,pub apple_pay_certificates: Option<serde_json::Value>,pub apple_pay_certificates_encrypted: Option<Encryption>,pub revenue_recovery_config: Option<RevenueRecoveryConfig>,diff --git a/crates/diesel_models/src/schema_v2.rs b/crates/diesel_models/src/schema_v2.rsindex 3462b5df17..13b60133a5 100644--- a/crates/diesel_models/src/schema_v2.rs+++ b/crates/diesel_models/src/schema_v2.rs@@ -334,6 +334,8 @@ diesel::table! {#[max_length = 16]split_txns_enabled -> Nullable<Varchar>,revenue_recovery_config -> Nullable<Jsonb>,+ #[max_length = 64]+ revenue_recovery_trigger_model -> Nullable<Varchar>,}}diff --git a/crates/hyperswitch_domain_models/src/business_profile.rs b/crates/hyperswitch_domain_models/src/business_profile.rsindex d4f08c2030..3ed45cebd8 100644--- a/crates/hyperswitch_domain_models/src/business_profile.rs+++ b/crates/hyperswitch_domain_models/src/business_profile.rs@@ -689,6 +689,7 @@ pub struct Profile {pub merchant_category_code: Option<api_enums::MerchantCategoryCode>,pub merchant_country_code: Option<common_types::payments::MerchantCountryCode>,pub split_txns_enabled: common_enums::SplitTxnsEnabled,+ pub revenue_recovery_trigger_model: common_enums::RevenueRecoveryTriggerModel,pub is_manual_retry_enabled: Option<bool>,pub billing_processor_id: Option<common_utils::id_type::MerchantConnectorAccountId>,pub surcharge_connector_details: Option<SurchargeConnectorDetails>,@@ -751,6 +752,7 @@ pub struct ProfileSetter {pub merchant_category_code: Option<api_enums::MerchantCategoryCode>,pub merchant_country_code: Option<common_types::payments::MerchantCountryCode>,pub split_txns_enabled: common_enums::SplitTxnsEnabled,+ pub revenue_recovery_trigger_model: common_enums::RevenueRecoveryTriggerModel,pub billing_processor_id: Option<common_utils::id_type::MerchantConnectorAccountId>,pub surcharge_connector_details: Option<SurchargeConnectorDetails>,pub revenue_recovery_config: Option<RevenueRecoveryConfig>,@@ -817,6 +819,7 @@ impl From<ProfileSetter> for Profile {merchant_category_code: value.merchant_category_code,merchant_country_code: value.merchant_country_code,split_txns_enabled: value.split_txns_enabled,+ revenue_recovery_trigger_model: value.revenue_recovery_trigger_model,is_manual_retry_enabled: None,billing_processor_id: value.billing_processor_id,surcharge_connector_details: value.surcharge_connector_details,@@ -882,6 +885,7 @@ pub struct ProfileDbBuilder {pub merchant_category_code: Option<api_enums::MerchantCategoryCode>,pub merchant_country_code: Option<common_types::payments::MerchantCountryCode>,pub split_txns_enabled: common_enums::SplitTxnsEnabled,+ pub revenue_recovery_trigger_model: common_enums::RevenueRecoveryTriggerModel,pub is_manual_retry_enabled: Option<bool>,pub billing_processor_id: Option<common_utils::id_type::MerchantConnectorAccountId>,pub surcharge_connector_details: Option<SurchargeConnectorDetails>,@@ -949,6 +953,7 @@ impl From<ProfileDbBuilder> for Profile {merchant_category_code: value.merchant_category_code,merchant_country_code: value.merchant_country_code,split_txns_enabled: value.split_txns_enabled,+ revenue_recovery_trigger_model: value.revenue_recovery_trigger_model,is_manual_retry_enabled: value.is_manual_retry_enabled,billing_processor_id: value.billing_processor_id,surcharge_connector_details: value.surcharge_connector_details,@@ -1324,6 +1329,7 @@ pub struct ProfileGeneralUpdate {pub merchant_country_code: Option<common_types::payments::MerchantCountryCode>,pub revenue_recovery_retry_algorithm_type: Option<common_enums::RevenueRecoveryAlgorithmType>,pub split_txns_enabled: Option<common_enums::SplitTxnsEnabled>,+ pub revenue_recovery_trigger_model: Option<common_enums::RevenueRecoveryTriggerModel>,pub billing_processor_id: Option<common_utils::id_type::MerchantConnectorAccountId>,pub surcharge_connector_details: Option<SurchargeConnectorDetails>,pub revenue_recovery_config: Option<RevenueRecoveryConfig>,diff --git a/crates/openapi/src/openapi_v2.rs b/crates/openapi/src/openapi_v2.rsindex 1f4ec82282..e98a3578f5 100644--- a/crates/openapi/src/openapi_v2.rs+++ b/crates/openapi/src/openapi_v2.rs@@ -1030,6 +1030,7 @@ Never share your secret api keys. Keep them guarded and secure.api_models::payments::AdditionalCardInfo,common_types::payments::RecoveryTransactionStatus,api_models::enums::RevenueRecoveryAlgorithmType,+ api_models::enums::RevenueRecoveryTriggerModel,api_models::enums::RevenueRecoveryABAlgorithm,api_models::enums::ProcessTrackerStatus,api_models::proxy::ProxyRequest,diff --git a/crates/router/src/core/admin.rs b/crates/router/src/core/admin.rsindex 38736e4d04..6ec4456f3e 100644--- a/crates/router/src/core/admin.rs+++ b/crates/router/src/core/admin.rs@@ -3807,6 +3807,11 @@ impl ProfileCreateBridge for api::ProfileCreate {helpers::validate_session_expiry(session_expiry.to_owned())?;}+ validate_retry_config_of_trigger_model(+ self.revenue_recovery_trigger_model.unwrap_or_default(),+ self.revenue_recovery_config.is_some(),+ )?;+// Generate a unique profile id// TODO: the profile_id should be generated from the profile_namelet profile_id = common_utils::generate_profile_id_of_default_length();@@ -3965,6 +3970,7 @@ impl ProfileCreateBridge for api::ProfileCreate {merchant_category_code: self.merchant_category_code,merchant_country_code: self.merchant_country_code,split_txns_enabled: self.split_txns_enabled.unwrap_or_default(),+ revenue_recovery_trigger_model: self.revenue_recovery_trigger_model.unwrap_or_default(),billing_processor_id: self.billing_processor_id,surcharge_connector_details: self.surcharge_connector_details@@ -4430,6 +4436,24 @@ impl ProfileUpdateBridge for api::ProfileUpdate {}}+/// A profile that follows external triggers has no billing connector account to hold its retry+/// limits, so they have to be on the profile.+#[cfg(feature = "v2")]+fn validate_retry_config_of_trigger_model(+ trigger_model: common_enums::RevenueRecoveryTriggerModel,+ has_retry_config: bool,+) -> RouterResult<()> {+ utils::when(+ trigger_model == common_enums::RevenueRecoveryTriggerModel::ExternalTriggers+ && !has_retry_config,+ || {+ Err(report!(errors::ApiErrorResponse::MissingRequiredField {+ field_name: "revenue_recovery_config".into(),+ }))+ },+ )+}+#[cfg(all(feature = "olap", feature = "v2"))]#[async_trait::async_trait]impl ProfileUpdateBridge for api::ProfileUpdate {@@ -4443,6 +4467,13 @@ impl ProfileUpdateBridge for api::ProfileUpdate {helpers::validate_session_expiry(session_expiry.to_owned())?;}+ validate_retry_config_of_trigger_model(+ self.revenue_recovery_trigger_model+ .unwrap_or(business_profile.revenue_recovery_trigger_model),+ self.revenue_recovery_config.is_some()+ || business_profile.revenue_recovery_config.is_some(),+ )?;+if let Some(url) = self.webhook_details.as_ref()@@ -4591,6 +4622,7 @@ impl ProfileUpdateBridge for api::ProfileUpdate {merchant_country_code: self.merchant_country_code,revenue_recovery_retry_algorithm_type,split_txns_enabled: self.split_txns_enabled,+ revenue_recovery_trigger_model: self.revenue_recovery_trigger_model,billing_processor_id: self.billing_processor_id,surcharge_connector_details: self.surcharge_connector_detailsdiff --git a/crates/router/src/types/api/admin.rs b/crates/router/src/types/api/admin.rsindex 2846bcd883..3b76f651a2 100644--- a/crates/router/src/types/api/admin.rs+++ b/crates/router/src/types/api/admin.rs@@ -383,6 +383,7 @@ impl ForeignTryFrom<domain::Profile> for ProfileResponse {merchant_category_code: item.merchant_category_code,merchant_country_code: item.merchant_country_code,split_txns_enabled: item.split_txns_enabled,+ revenue_recovery_trigger_model: item.revenue_recovery_trigger_model,revenue_recovery_retry_algorithm_type: item.revenue_recovery_retry_algorithm_type,billing_processor_id: item.billing_processor_id,surcharge_connector_details: itemdiff --git a/crates/storage_impl/src/business_profile.rs b/crates/storage_impl/src/business_profile.rsindex 2c2efca9df..70a23aad60 100644--- a/crates/storage_impl/src/business_profile.rs+++ b/crates/storage_impl/src/business_profile.rs@@ -1774,6 +1774,7 @@ impl ForeignFrom<domain::ProfileUpdate> for ProfileUpdateInternal {merchant_country_code,revenue_recovery_retry_algorithm_type,split_txns_enabled,+ revenue_recovery_trigger_model,billing_processor_id,surcharge_connector_details,revenue_recovery_config,@@ -1832,6 +1833,7 @@ impl ForeignFrom<domain::ProfileUpdate> for ProfileUpdateInternal {merchant_category_code,merchant_country_code,split_txns_enabled,+ revenue_recovery_trigger_model,billing_processor_id,surcharge_connector_details,apple_pay_certificates: None,@@ -1895,6 +1897,7 @@ impl ForeignFrom<domain::ProfileUpdate> for ProfileUpdateInternal {merchant_category_code: None,merchant_country_code: None,split_txns_enabled: None,+ revenue_recovery_trigger_model: None,billing_processor_id: None,surcharge_connector_details: None,apple_pay_certificates: None,@@ -1956,6 +1959,7 @@ impl ForeignFrom<domain::ProfileUpdate> for ProfileUpdateInternal {merchant_category_code: None,merchant_country_code: None,split_txns_enabled: None,+ revenue_recovery_trigger_model: None,billing_processor_id: None,surcharge_connector_details: None,apple_pay_certificates: None,@@ -2017,6 +2021,7 @@ impl ForeignFrom<domain::ProfileUpdate> for ProfileUpdateInternal {merchant_category_code: None,merchant_country_code: None,split_txns_enabled: None,+ revenue_recovery_trigger_model: None,billing_processor_id: None,surcharge_connector_details: None,apple_pay_certificates: None,@@ -2078,6 +2083,7 @@ impl ForeignFrom<domain::ProfileUpdate> for ProfileUpdateInternal {merchant_category_code: None,merchant_country_code: None,split_txns_enabled: None,+ revenue_recovery_trigger_model: None,billing_processor_id: None,surcharge_connector_details: None,apple_pay_certificates: None,@@ -2139,6 +2145,7 @@ impl ForeignFrom<domain::ProfileUpdate> for ProfileUpdateInternal {merchant_category_code: None,merchant_country_code: None,split_txns_enabled: None,+ revenue_recovery_trigger_model: None,billing_processor_id: None,surcharge_connector_details: None,apple_pay_certificates: None,@@ -2200,6 +2207,7 @@ impl ForeignFrom<domain::ProfileUpdate> for ProfileUpdateInternal {merchant_category_code: None,merchant_country_code: None,split_txns_enabled: None,+ revenue_recovery_trigger_model: None,billing_processor_id: None,surcharge_connector_details: None,apple_pay_certificates: None,@@ -2261,6 +2269,7 @@ impl ForeignFrom<domain::ProfileUpdate> for ProfileUpdateInternal {merchant_category_code: None,merchant_country_code: None,split_txns_enabled: None,+ revenue_recovery_trigger_model: None,billing_processor_id: None,surcharge_connector_details: None,apple_pay_certificates: None,@@ -2322,6 +2331,7 @@ impl ForeignFrom<domain::ProfileUpdate> for ProfileUpdateInternal {merchant_category_code: None,merchant_country_code: None,split_txns_enabled: None,+ revenue_recovery_trigger_model: None,billing_processor_id: None,surcharge_connector_details: None,apple_pay_certificates: None,@@ -2384,6 +2394,7 @@ impl ForeignFrom<domain::ProfileUpdate> for ProfileUpdateInternal {merchant_category_code: None,merchant_country_code: None,split_txns_enabled: None,+ revenue_recovery_trigger_model: None,billing_processor_id: None,surcharge_connector_details: None,apple_pay_certificates: None,@@ -2446,6 +2457,7 @@ impl ForeignFrom<domain::ProfileUpdate> for ProfileUpdateInternal {merchant_category_code: None,merchant_country_code: None,split_txns_enabled: None,+ revenue_recovery_trigger_model: None,billing_processor_id: None,surcharge_connector_details: None,apple_pay_certificates,@@ -2531,6 +2543,7 @@ impl Conversion for domain::Profile {merchant_country_code: self.merchant_country_code,dispute_polling_interval: None,split_txns_enabled: Some(self.split_txns_enabled),+ revenue_recovery_trigger_model: Some(self.revenue_recovery_trigger_model),is_manual_retry_enabled: None,auto_fallback_capture_method: None,is_l2_l3_enabled: None,@@ -2642,6 +2655,9 @@ impl Conversion for domain::Profile {merchant_category_code: item.merchant_category_code,merchant_country_code: item.merchant_country_code,split_txns_enabled: item.split_txns_enabled.unwrap_or_default(),+ revenue_recovery_trigger_model: item+ .revenue_recovery_trigger_model+ .unwrap_or_default(),is_manual_retry_enabled: item.is_manual_retry_enabled,billing_processor_id: item.billing_processor_id,surcharge_connector_details: item.surcharge_connector_details,@@ -2720,6 +2736,7 @@ impl Conversion for domain::Profile {is_l2_l3_enabled: None,merchant_country_code: self.merchant_country_code,split_txns_enabled: Some(self.split_txns_enabled),+ revenue_recovery_trigger_model: Some(self.revenue_recovery_trigger_model),billing_processor_id: self.billing_processor_id,surcharge_connector_details: self.surcharge_connector_details,revenue_recovery_config: self.revenue_recovery_config,diff --git a/v2_compatible_migrations/2026-11-01-100000_add_revenue_recovery_trigger_model_to_business_profile/down.sql b/v2_compatible_migrations/2026-11-01-100000_add_revenue_recovery_trigger_model_to_business_profile/down.sqlnew file mode 100644index 0000000000..daf64497dd--- /dev/null+++ b/v2_compatible_migrations/2026-11-01-100000_add_revenue_recovery_trigger_model_to_business_profile/down.sql@@ -0,0 +1,3 @@+-- This file should undo anything in `up.sql`+ALTER TABLE business_profile+DROP COLUMN IF EXISTS revenue_recovery_trigger_model;diff --git a/v2_compatible_migrations/2026-11-01-100000_add_revenue_recovery_trigger_model_to_business_profile/up.sql b/v2_compatible_migrations/2026-11-01-100000_add_revenue_recovery_trigger_model_to_business_profile/up.sqlnew file mode 100644index 0000000000..9bab407c05--- /dev/null+++ b/v2_compatible_migrations/2026-11-01-100000_add_revenue_recovery_trigger_model_to_business_profile/up.sql@@ -0,0 +1,3 @@+-- Your SQL goes here+ALTER TABLE business_profile+ADD COLUMN IF NOT EXISTS revenue_recovery_trigger_model VARCHAR(64);