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(ucs): honor Superposition configuration for incoming webhooks (#15292)

Amitsingh Tanwardd0011b87dfe
diff --git a/config/superposition_seed.toml b/config/superposition_seed.toml
index 47e0aeef81..58e38f7339 100644
--- a/config/superposition_seed.toml
+++ b/config/superposition_seed.toml
@@ -2734,7 +2734,7 @@ pt_mapping_outgoing_connector_webhooks = { value = { default_mapping = { frequen
"ucs.shadow_kill_switch_threshold" = { value = 1, schema = { type = "integer", minimum = 1, maximum = 9223372036854775807 }, description = "Global shadow request-failure count at which UCS shadow proxying stops; shadow_disabled also stops shadow traffic independently", change_reason = "UCS shadow kill switch threshold" }
[dimensions]
-flow_name = { position = 21, schema = { type = "string" }, type = "REGULAR", description = "Payment flow name (e.g. Authorize, PSync, Execute, RSync, Webhooks)", change_reason = "Initial setup" }
+flow_name = { position = 22, schema = { type = "string" }, type = "REGULAR", description = "Payment flow name (e.g. Authorize, PSync, Execute, RSync, Webhooks)", change_reason = "Initial setup" }
always_collect_billing_details_from_wallet_connector = { position = 7, schema = { type = "boolean" }, type = "REGULAR" }
always_collect_shipping_details_from_wallet_connector = { position = 8, schema = { type = "boolean" }, type = "REGULAR" }
connector = { position = 1, schema = { enum = [
diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rs
index 00aee6770d..6bb1992145 100644
--- a/crates/router/src/core/payments/helpers.rs
+++ b/crates/router/src/core/payments/helpers.rs
@@ -3055,34 +3055,49 @@ pub async fn should_execute_based_on_rollout_with_precedence_from_superposition(
superposition_key: &str,
context: Option<external_services::superposition::ConfigContext>,
) -> RouterResult<RolloutExecutionResult> {
+ let mut execution_result = should_execute_based_on_rollout_from_superposition::<
+ RolloutConfig,
+ RolloutExecutionResult,
+ >(state, superposition_key, context.as_ref())
+ .await?;
+ if execution_result.should_execute {
+ execution_result.proxy_override = build_rollout_proxy_override(state);
+ }
+ Ok(execution_result)
+}
+
+/// Fetches and evaluates a Superposition rollout config, preserving the config's result type.
+/// Missing or invalid configuration defaults to not executing, without falling back to DB.
+pub async fn should_execute_based_on_rollout_from_superposition<C, R>(
+ state: &SessionState,
+ superposition_key: &str,
+ context: Option<&external_services::superposition::ConfigContext>,
+) -> RouterResult<R>
+where
+ C: DeserializeOwned,
+ R: From<C> + Default,
+{
match state
.superposition_service
- .get_config_value::<serde_json::Value>(superposition_key, context.as_ref(), None)
+ .get_config_value::<serde_json::Value>(superposition_key, context, None)
.await
{
- Ok(json_value) => {
- let mut execution_result = json_value
- .parse_value::<RolloutConfig>("RolloutConfig")
- .map(RolloutExecutionResult::from)
- .map_err(|err| {
- logger::error!(
- error = ?err,
- "Failed to parse superposition rollout config. Defaulting to not execute."
- );
- RolloutExecutionResult::default()
- })
- .unwrap_or_default();
- if execution_result.should_execute {
- execution_result.proxy_override = build_rollout_proxy_override(state);
- }
- Ok(execution_result)
- }
+ Ok(json_value) => Ok(json_value
+ .parse_value::<C>("RolloutConfig")
+ .map(R::from)
+ .unwrap_or_else(|err| {
+ logger::error!(
+ error = ?err,
+ "Failed to parse superposition rollout config. Defaulting to not execute."
+ );
+ R::default()
+ })),
Err(err) => {
logger::error!(
error = ?err,
"Failed to fetch rollout config from superposition. Defaulting to not execute."
);
- Ok(RolloutExecutionResult::default())
+ Ok(R::default())
}
}
}
diff --git a/crates/router/src/core/unified_connector_service.rs b/crates/router/src/core/unified_connector_service.rs
index a5d4b61f09..2728ef348a 100644
--- a/crates/router/src/core/unified_connector_service.rs
+++ b/crates/router/src/core/unified_connector_service.rs
@@ -58,7 +58,9 @@ use crate::{
helpers::{
get_ucs_config_source, get_ucs_enabled_mode_from_superposition,
is_config_flag_enabled, is_googlepay_predecrypted_flow_supported,
- should_execute_based_on_rollout, should_execute_based_on_rollout_with_precedence,
+ should_execute_based_on_rollout,
+ should_execute_based_on_rollout_from_superposition,
+ should_execute_based_on_rollout_with_precedence,
should_execute_based_on_rollout_with_precedence_from_superposition,
MerchantConnectorAccountType, ProxyOverride, RolloutExecutionResult,
WebhookRolloutConfig, WebhookRolloutExecutionResult,
@@ -1858,25 +1860,18 @@ pub async fn should_call_unified_connector_service_for_webhooks(
let flow_name = "Webhooks";
- // Check UCS availability using idiomatic helper
- let ucs_availability = check_ucs_availability(state).await;
-
- let rollout_key = format!(
- "{}_{}_{}_{}",
- consts::UCS_ROLLOUT_PERCENT_CONFIG_PREFIX,
- merchant_id,
- connector_name,
- flow_name
- );
-
// For webhooks, there is no previous gateway system to consider (webhooks are stateless)
let previous_gateway = None;
- let rollout_result = should_execute_based_on_rollout::<
- WebhookRolloutConfig,
- WebhookRolloutExecutionResult,
- >(state, &rollout_key)
- .await?;
+ let config_source = get_ucs_config_source(state);
+ let (ucs_availability, rollout_result) = match config_source {
+ UcsConfigSource::Database => {
+ should_call_ucs_for_webhooks_via_db(state, processor, connector_name).await?
+ }
+ UcsConfigSource::Superposition => {
+ should_call_ucs_for_webhooks_via_superposition(state, processor, connector_name).await?
+ }
+ };
// Use the same decision logic as payments, with no call_connector_action to consider
let (gateway_system, execution_path) = if ucs_availability == UcsAvailability::Disabled {
@@ -1892,6 +1887,7 @@ pub async fn should_call_unified_connector_service_for_webhooks(
};
router_env::logger::info!(
+ ?config_source,
"Webhook gateway decision: gateway={:?}, execution_path={:?} - merchant_id={}, connector={}, flow={}",
gateway_system,
execution_path,
@@ -1903,6 +1899,55 @@ pub async fn should_call_unified_connector_service_for_webhooks(
Ok((execution_path, rollout_result.webhook_flows))
}
+async fn should_call_ucs_for_webhooks_via_db(
+ state: &SessionState,
+ processor: &Processor,
+ connector_name: &str,
+) -> RouterResult<(UcsAvailability, WebhookRolloutExecutionResult)> {
+ let ucs_availability = check_ucs_availability(state).await;
+ let rollout_key = format!(
+ "{}_{}_{}_Webhooks",
+ consts::UCS_ROLLOUT_PERCENT_CONFIG_PREFIX,
+ processor.get_account().get_id().get_string_repr(),
+ connector_name,
+ );
+ let rollout_result = should_execute_based_on_rollout::<
+ WebhookRolloutConfig,
+ WebhookRolloutExecutionResult,
+ >(state, &rollout_key)
+ .await?;
+ Ok((ucs_availability, rollout_result))
+}
+
+async fn should_call_ucs_for_webhooks_via_superposition(
+ state: &SessionState,
+ processor: &Processor,
+ connector_name: &str,
+) -> RouterResult<(UcsAvailability, WebhookRolloutExecutionResult)> {
+ let ucs_availability = check_ucs_availability_from_superposition(state).await;
+ let context = superposition::ConfigContext::new()
+ .with(
+ "organization_id",
+ processor.get_account().get_org_id().get_string_repr(),
+ )
+ .with(
+ "processor_merchant_id",
+ processor.get_account().get_id().get_string_repr(),
+ )
+ .with("connector", connector_name)
+ .with("flow_name", "Webhooks");
+ let rollout_result = should_execute_based_on_rollout_from_superposition::<
+ WebhookRolloutConfig,
+ WebhookRolloutExecutionResult,
+ >(
+ state,
+ consts::superposition::UCS_ROLLOUT_CONFIG,
+ Some(&context),
+ )
+ .await?;
+ Ok((ucs_availability, rollout_result))
+}
+
/// On a redirect-complete callback the inbound request carries only redirect params, so
/// `payment_method_data` is `None`. UCS still requires `payment_method` on the authorize call,
/// so rebuild a minimal one from the attempt's payment method type.