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(payouts): add Superposition kill switch with OMP scopes (#15181)
Sakil Mostak866865ce84a9
diff --git a/config/superposition_seed.toml b/config/superposition_seed.tomlindex 37c06d0b77..c2c146c877 100644--- a/config/superposition_seed.toml+++ b/config/superposition_seed.toml@@ -2557,6 +2557,7 @@ client_session_validation_enabled = { value = true, schema = { type = "boolean""dynamic_fields.wallet.mifinity.language_preference._validation_rule_type" = { value = "no_validation", schema = { type = "string" } }"payments.enable_extended_card_bin" = { value = false, schema = { type = "boolean" }, description = "Whether to use extended card BIN (8-digit) for payment method data", change_reason = "Initial setup" }"payouts.gsm_payout_call" = { value = false, schema = { type = "boolean" }, description = "Whether to call GSM for payout retries", change_reason = "Initial setup" }+"payouts.kill_switch" = { value = false, schema = { type = "boolean" }, description = "Stop payout creation, confirmation, updates, cancellation and fulfillment when true. Retrieval, status sync, listing, filters, aggregates, manual updates and payout-link rendering remain available. Override by organization_id, organization_id and merchant IDs, or organization_id, merchant IDs and profile_id.", change_reason = "Add organization, merchant and profile scoped payout kill switch" }"payments.implicit_customer_update" = { value = false, schema = { type = "boolean" }, description = "Whether to implicitly update customer details on payment", change_reason = "Initial setup" }"payments.block_implicit_customer_creation" = { value = false, schema = { type = "boolean" }, description = "Whether payments must reject implicit creation of a missing customer for an organization", change_reason = "Decouple implicit customer creation from PM modular eligibility" }"webhooks.incoming_webhook_disabled_events" = { value = false, schema = { type = "boolean" }, description = "Whether a specific incoming webhook event is disabled for a given connector", change_reason = "Initial setup" }diff --git a/crates/router/src/consts.rs b/crates/router/src/consts.rsindex 5c336b593c..90580959b0 100644--- a/crates/router/src/consts.rs+++ b/crates/router/src/consts.rs@@ -516,6 +516,8 @@ pub mod superposition {pub const ENABLE_EXTENDED_CARD_BIN: &str = "payments.enable_extended_card_bin";/// Max auto payout retries configuration keypub const MAX_AUTO_PAYOUT_RETRIES: &str = "payouts.max_auto_payout_retries";+ /// Stops payout creation, confirmation, update, cancellation, and fulfillment at OMP scope.+ pub const PAYOUT_KILL_SWITCH: &str = "payouts.kill_switch";/// GSM payout call configuration key (scoped by merchant, profile, and payout retry type)pub const GSM_PAYOUT_CALL: &str = "payouts.gsm_payout_call";/// Disable vault tokenization configuration keydiff --git a/crates/router/src/core/configs/dimension_config.rs b/crates/router/src/core/configs/dimension_config.rsindex 22c35661f3..c1c9b31aed 100644--- a/crates/router/src/core/configs/dimension_config.rs+++ b/crates/router/src/core/configs/dimension_config.rs@@ -117,11 +117,12 @@ macro_rules! config {}};- // Primitive config variant (no helper function - use get_{{key_name}}() directly on Dimensions)+ // Primitive config variant. Optional generics allow dimensions beyond `requires` to vary.(superposition_key = $key:ident,output = $output:ty,default = $default:expr,+ $(generics = [$($generic:ident),+],)?requires = $requirement:ty,targeting_key = $targeting_type:ty) => {@@ -137,7 +138,7 @@ macro_rules! config {}}- impl $requirement {+ impl $(<$($generic),+>)? $requirement {pub async fn [<get_ $key:lower>](&self,storage: &dyn StorageInterface,@@ -395,6 +396,19 @@ impl DatabaseBackedConfig for CardTestingGuardConfig {const KEY: &'static str = "card_testing_guard_config";}+config! {+ superposition_key = PAYOUT_KILL_SWITCH,+ output = bool,+ default = false,+ 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+}++impl DatabaseBackedConfig for PayoutKillSwitch {+ const KEY: &'static str = "payout_kill_switch";+}+config! {superposition_key = GSM_PAYOUT_CALL,output = bool,diff --git a/crates/router/src/core/payouts.rs b/crates/router/src/core/payouts.rsindex dcd84280f3..d62855718c 100644--- a/crates/router/src/core/payouts.rs+++ b/crates/router/src/core/payouts.rs@@ -2,11 +2,14 @@use strum::IntoEnumIterator;use crate::core::payouts::gateway as payout_gateway;+#[cfg(feature = "v1")]+use crate::core::payouts::kill_switch::PayoutKillSwitch;pub mod access_token;pub mod gateway;#[cfg(feature = "v1")]pub mod guards;pub mod helpers;+pub mod kill_switch;#[cfg(feature = "v1")]pub mod proxy;#[cfg(feature = "payout_retry")]@@ -778,6 +781,7 @@ pub async fn payouts_confirm_core(profile_id,&payouts::PayoutRequest::PayoutCreateRequest(Box::new(req.to_owned())),&state.locale,+ true,)).await?;let payout_attempt = payout_data.payout_attempt.to_owned();@@ -849,6 +853,7 @@ pub async fn payouts_update_core(profile_id,&payouts::PayoutRequest::PayoutCreateRequest(Box::new(req.to_owned())),&state.locale,+ true,)).await?;@@ -925,6 +930,7 @@ pub async fn payouts_retrieve_core(profile_id,&payouts::PayoutRequest::PayoutRetrieveRequest(req.to_owned()),&state.locale,+ false,)).await?;let dimensions = dimension_state::Dimensions::new()@@ -976,6 +982,7 @@ pub async fn payouts_cancel_core(profile_id,&payouts::PayoutRequest::PayoutActionRequest(req.to_owned()),&state.locale,+ true,)).await?;@@ -1088,6 +1095,7 @@ pub async fn payouts_fulfill_core(profile_id,&payouts::PayoutRequest::PayoutActionRequest(req.to_owned()),&state.locale,+ true,)).await?;@@ -3799,18 +3807,22 @@ pub async fn make_payout_data(_platform: &domain::Platform,_auth_profile_id: Option<id_type::ProfileId>,_req: &payouts::PayoutRequest,- locale: &str,+ _locale: &str,+ _enforce_kill_switch: bool,) -> RouterResult<PayoutData> {todo!()}#[cfg(feature = "v1")]+/// Load payout data, checking the kill switch for mutation and standalone execution callers.+/// Retrieval, webhook delivery, and background status sync pass `false` to continue processing existing payouts.pub async fn make_payout_data(state: &SessionState,platform: &domain::Platform,auth_profile_id: Option<id_type::ProfileId>,req: &payouts::PayoutRequest,locale: &str,+ enforce_kill_switch: bool,) -> RouterResult<PayoutData> {let db = &*state.store;let merchant_id = platform.get_processor().get_account().get_id();@@ -3897,6 +3909,16 @@ pub async fn make_payout_data(.await.to_not_found_response(errors::ApiErrorResponse::PayoutNotFound)?;+ let profile_id = payout_attempt.profile_id.clone();++ // Validate the persisted profile before checking its scope or accessing payout data.+ let business_profile =+ validate_and_get_business_profile(state, platform.get_processor(), &profile_id).await?;+ match enforce_kill_switch {+ true => PayoutKillSwitch::ensure_payouts_enabled(state, platform, Some(&profile_id)).await,+ false => Ok(()),+ }?;+// Reject proxy mutations before normal method or locker resolution.payout_attempt.execution_kind@@ -3949,11 +3971,6 @@ pub async fn make_payout_data(.await.transpose()?.and_then(|c| c);- let profile_id = payout_attempt.profile_id.clone();-- // Validate whether profile_id passed in request is valid and is linked to the merchant- let business_profile =- validate_and_get_business_profile(state, platform.get_processor(), &profile_id).await?;let payout_method_data_req = match req {payouts::PayoutRequest::PayoutCreateRequest(r) => r.payout_method_data.to_owned(),payouts::PayoutRequest::PayoutActionRequest(_) => {diff --git a/crates/router/src/core/payouts/kill_switch.rs b/crates/router/src/core/payouts/kill_switch.rsnew file mode 100644index 0000000000..1a24edc78c--- /dev/null+++ b/crates/router/src/core/payouts/kill_switch.rs@@ -0,0 +1,55 @@+use common_utils::id_type;+use error_stack::report;++pub use crate::core::configs::dimension_config::PayoutKillSwitch;+use crate::{+ core::{+ configs::dimension_state,+ errors::{self, RouterResult},+ },+ routes::SessionState,+ types::domain,+};++impl PayoutKillSwitch {+ /// Reject payout mutations when the switch resolves to true for their available OMP dimensions.+ pub async fn ensure_payouts_enabled(+ state: &SessionState,+ platform: &domain::Platform,+ profile_id: Option<&id_type::ProfileId>,+ ) -> RouterResult<()> {+ let dimensions = dimension_state::Dimensions::new()+ .with_organization_id(platform.get_processor().get_account().get_org_id().clone())+ .with_processor_merchant_id(platform.get_processor().get_processor_merchant_id())+ .with_provider_merchant_id(platform.get_provider().get_provider_merchant_id());++ let disabled = match profile_id {+ Some(profile_id) => {+ dimensions+ .with_profile_id(profile_id.clone())+ .get_payout_kill_switch(+ state.store.as_ref(),+ state.superposition_service.as_ref(),+ None,+ )+ .await+ }+ None => {+ dimensions+ .get_payout_kill_switch(+ state.store.as_ref(),+ state.superposition_service.as_ref(),+ None,+ )+ .await+ }+ };++ match disabled {+ true => Err(report!(errors::ApiErrorResponse::PreconditionFailed {+ message: "Payouts are disabled by configuration".to_string(),+ })),+ false => Ok(()),+ }+ }+}diff --git a/crates/router/src/core/payouts/proxy.rs b/crates/router/src/core/payouts/proxy.rsindex aff49e5ffd..bc8e2f02bb 100644--- a/crates/router/src/core/payouts/proxy.rs+++ b/crates/router/src/core/payouts/proxy.rs@@ -14,6 +14,7 @@ use hyperswitch_masking::PeekInterface;use super::{gateway::context::RouterGatewayContext,+ kill_switch::PayoutKillSwitch,validator::{self, invalid_payout_request, validate_payout_condition},PayoutData,};@@ -209,6 +210,7 @@ impl ExternalVaultPayout<'_> {) -> RouterResponse<payouts::PayoutCreateResponse> {let state = self.state;let platform = self.platform;+ PayoutKillSwitch::ensure_payouts_enabled(state, platform, Some(profile.get_id())).await?;let input =Box::pin(self.validate_proxy_create_request(req, profile, provider_profile)).await?;self.ensure_proxy_transport_available()?;diff --git a/crates/router/src/core/payouts/validator.rs b/crates/router/src/core/payouts/validator.rsindex 5063200d14..6aa58ca369 100644--- a/crates/router/src/core/payouts/validator.rs+++ b/crates/router/src/core/payouts/validator.rs@@ -18,7 +18,9 @@ use url::Url;use super::helpers;#[cfg(feature = "v1")]-use crate::core::payment_methods::cards::get_pm_list_context;+use crate::core::{+ payment_methods::cards::get_pm_list_context, payouts::kill_switch::PayoutKillSwitch,+};use crate::{core::{configs::dimension_state,@@ -193,6 +195,19 @@ pub async fn validate_create_request(None => Ok(()),}?;+ // Resolve the profile and kill switch before creating customers or resolving payout methods.+ let business_profile = core_utils::get_profile_from_business_details(+ req.business_country,+ req.business_label.as_ref(),+ platform.get_processor(),+ req.profile_id.as_ref(),+ &*state.store,+ )+ .await?;+ PayoutKillSwitch::ensure_payouts_enabled(state, platform, Some(business_profile.get_id()))+ .await?;+ let profile_id = business_profile.get_id().to_owned();+// Fetch customer details (merge of loose fields + customer object) and create DB entrylet customer_in_request = helpers::get_customer_details_from_request(req);let customer = if customer_in_request.customer_id.is_some()@@ -207,17 +222,6 @@ pub async fn validate_create_request(None};- // Fetch the profile once and hand it back, so payout creation doesn't fetch it again- let business_profile = core_utils::get_profile_from_business_details(- req.business_country,- req.business_label.as_ref(),- platform.get_processor(),- req.profile_id.as_ref(),- &*state.store,- )- .await?;- let profile_id = business_profile.get_id().to_owned();-let payment_method: Option<PaymentMethod> =match (req.payout_token.as_ref(), req.payout_method_id.clone()) {(Some(_), Some(_)) => Err(report!(errors::ApiErrorResponse::InvalidRequestData {diff --git a/crates/router/src/core/webhooks/incoming.rs b/crates/router/src/core/webhooks/incoming.rsindex fb0e6352ef..f2f04f180b 100644--- a/crates/router/src/core/webhooks/incoming.rs+++ b/crates/router/src/core/webhooks/incoming.rs@@ -1286,6 +1286,7 @@ async fn process_payout_incoming_webhook(None,&action_req,common_utils::consts::DEFAULT_LOCALE,+ false,)).await?;diff --git a/crates/router/src/workflows/attach_payout_account_workflow.rs b/crates/router/src/workflows/attach_payout_account_workflow.rsindex 457b027666..7c7d19f56c 100644--- a/crates/router/src/workflows/attach_payout_account_workflow.rs+++ b/crates/router/src/workflows/attach_payout_account_workflow.rs@@ -65,6 +65,7 @@ impl ProcessTrackerWorkflow<SessionState> for AttachPayoutAccountWorkflow {None,&request,DEFAULT_LOCALE,+ true,)).await?;diff --git a/crates/router/src/workflows/outgoing_webhook_retry.rs b/crates/router/src/workflows/outgoing_webhook_retry.rsindex 6ae7b9a5bd..9c7d1b3d7b 100644--- a/crates/router/src/workflows/outgoing_webhook_retry.rs+++ b/crates/router/src/workflows/outgoing_webhook_retry.rs@@ -789,6 +789,7 @@ async fn get_outgoing_webhook_content_and_event_type(None,&request,DEFAULT_LOCALE,+ false,)).await?;diff --git a/crates/router/src/workflows/payout_sync.rs b/crates/router/src/workflows/payout_sync.rsindex 5734cb092e..6ce418a4ac 100644--- a/crates/router/src/workflows/payout_sync.rs+++ b/crates/router/src/workflows/payout_sync.rs@@ -80,6 +80,7 @@ impl ProcessTrackerWorkflow<SessionState> for PayoutSyncWorkFlow {None,&request,DEFAULT_LOCALE,+ false,)).await?;