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(ucs): add connector_decline_threshold and make kill switch logs alertable (#14395)

gopikrishna000fb366ef9755d
diff --git a/crates/external_services/src/grpc_client.rs b/crates/external_services/src/grpc_client.rs
index a5481eeadc..e5b8ea8575 100644
--- a/crates/external_services/src/grpc_client.rs
+++ b/crates/external_services/src/grpc_client.rs
@@ -24,6 +24,7 @@ pub mod semantic_boundary;
use std::{fmt::Debug, sync::Arc};
+use common_enums::{PaymentMethod, PaymentMethodType};
#[cfg(feature = "dynamic_routing")]
use common_utils::consts;
use common_utils::{id_type, ucs_types};
@@ -211,6 +212,12 @@ pub struct GrpcHeadersUcs {
proxy_name: Option<&'static str>,
/// Config override as JSON string to pass to UCS
config_override: Option<String>,
+ /// Sent as `x-payment-method` / `x-payment-method-type` so UCS can attribute the call
+ /// (its rollout scope includes the payment method). `None` where the flow has no
+ /// payment method: access-token fetch, FRM notification, incoming webhooks, surcharge
+ /// calculation, notify-connector, account-updater refresh.
+ payment_method: Option<PaymentMethod>,
+ payment_method_type: Option<PaymentMethodType>,
}
/// Type aliase for GrpcHeaders builder in initial stage
@@ -224,6 +231,8 @@ pub type GrpcHeadersUcsBuilderInitial = GrpcHeadersUcsBuilder<(
(Option<bool>,),
(Option<&'static str>,),
(Option<String>,),
+ (),
+ (),
)>;
/// Type aliase for GrpcHeaders builder in intermediate stage
pub type GrpcHeadersUcsBuilderFinal = GrpcHeadersUcsBuilder<(
@@ -236,6 +245,8 @@ pub type GrpcHeadersUcsBuilderFinal = GrpcHeadersUcsBuilder<(
(Option<bool>,),
(Option<&'static str>,),
(Option<String>,),
+ (Option<PaymentMethod>,),
+ (Option<PaymentMethodType>,),
)>;
/// struct to represent set of Lineage ids
diff --git a/crates/external_services/src/grpc_client/unified_connector_service.rs b/crates/external_services/src/grpc_client/unified_connector_service.rs
index 05dd46ac95..3e23f7e513 100644
--- a/crates/external_services/src/grpc_client/unified_connector_service.rs
+++ b/crates/external_services/src/grpc_client/unified_connector_service.rs
@@ -1701,6 +1701,8 @@ fn build_grpc_headers_internal(
shadow_mode,
proxy_name,
config_override,
+ payment_method,
+ payment_method_type,
} = grpc_headers;
let mut metadata = MetadataMap::new();
@@ -1799,6 +1801,26 @@ fn build_grpc_headers_internal(
);
};
+ if let Some(payment_method) = payment_method {
+ metadata.append(
+ common_utils_consts::X_PAYMENT_METHOD,
+ parse(
+ common_utils_consts::X_PAYMENT_METHOD,
+ &payment_method.to_string(),
+ )?,
+ );
+ };
+
+ if let Some(payment_method_type) = payment_method_type {
+ metadata.append(
+ common_utils_consts::X_PAYMENT_METHOD_TYPE,
+ parse(
+ common_utils_consts::X_PAYMENT_METHOD_TYPE,
+ &payment_method_type.to_string(),
+ )?,
+ );
+ };
+
if let Some(ref request_id) = request_id {
metadata.append(
common_utils_consts::X_REQUEST_ID,
diff --git a/crates/hyperswitch_interfaces/src/unified_connector_service/transformers.rs b/crates/hyperswitch_interfaces/src/unified_connector_service/transformers.rs
index c9c3117d33..dfddfb835c 100644
--- a/crates/hyperswitch_interfaces/src/unified_connector_service/transformers.rs
+++ b/crates/hyperswitch_interfaces/src/unified_connector_service/transformers.rs
@@ -2536,7 +2536,11 @@ pub enum UcsKillSwitchReason {
/// The connector rejected the request. May be a legitimate decline or a request UCS built
/// wrongly — indistinguishable at this layer, so we trip conservatively because falling back
/// to the battle-tested direct path is always safe.
- ConnectorOutcome,
+ ConnectorRejected,
+ /// UCS answered gRPC OK with a connector 2xx, and the connector still refused the payment.
+ /// A business outcome rather than a failure: the issuer would say the same on the direct
+ /// path, so this is counted against its own threshold.
+ ConnectorDeclined,
}
impl UnifiedConnectorServiceError {
@@ -2615,7 +2619,7 @@ impl UnifiedConnectorServiceError {
// wrongly — indistinguishable here. We trip conservatively: a false bypass to the
// direct path is safe (it served merchants for years), while a missed trip leaves
// merchants on a potentially broken UCS path.
- Self::ConnectorError(_) => Some(UcsKillSwitchReason::ConnectorOutcome),
+ Self::ConnectorError(_) => Some(UcsKillSwitchReason::ConnectorRejected),
// Per-flow failure markers carrying no further detail.
Self::WebhookProcessingFailure
diff --git a/crates/router/src/core/account_updater/refresh.rs b/crates/router/src/core/account_updater/refresh.rs
index 63970009b9..c129c3c4e0 100644
--- a/crates/router/src/core/account_updater/refresh.rs
+++ b/crates/router/src/core/account_updater/refresh.rs
@@ -51,6 +51,8 @@ pub async fn request_account_updater_refresh(
let grpc_headers = state
.get_grpc_headers_ucs(ExecutionMode::Primary)
+ .payment_method(None)
+ .payment_method_type(None)
.external_vault_proxy_metadata(None)
.merchant_reference_id(None)
.resource_id(None)
diff --git a/crates/router/src/core/authentication.rs b/crates/router/src/core/authentication.rs
index 09392dfff3..2b04f489d1 100644
--- a/crates/router/src/core/authentication.rs
+++ b/crates/router/src/core/authentication.rs
@@ -378,7 +378,9 @@ pub async fn perform_pre_authentication(
#[cfg(feature = "v1")]
struct ProxyUcsGatewayContext {
- execution_mode: common_enums::ExecutionMode,
+ /// The gate's read of this scope's rollout config, so a failure on the proxy path counts
+ /// against the threshold the gate used. Carries the execution mode.
+ rollout_settings: unified_connector_service::kill_switch::RolloutSettings,
session_state: SessionState,
platform: domain::Platform,
external_vault_merchant_connector_account: payments_core::helpers::MerchantConnectorAccountType,
@@ -399,7 +401,7 @@ async fn resolve_proxy_ucs_gateway_and_vault_mca<PayF: Clone, RdF: Clone, T, R>(
where
R: Send + Sync + Clone,
{
- let (execution_path, updated_state) =
+ let (execution_path, updated_state, rollout_result) =
unified_connector_service::should_call_unified_connector_service(
state,
processor,
@@ -468,7 +470,13 @@ where
));
Ok(Some(ProxyUcsGatewayContext {
- execution_mode,
+ rollout_settings: unified_connector_service::kill_switch::RolloutSettings {
+ execution_mode,
+ kill_switch_enabled: rollout_result.kill_switch_enabled,
+ kill_switch_threshold: rollout_result.kill_switch_threshold,
+ connector_decline_threshold: rollout_result.connector_decline_threshold,
+ rollout_scope: rollout_result.rollout_scope.clone(),
+ },
session_state: updated_state,
platform,
external_vault_merchant_connector_account,
@@ -496,7 +504,7 @@ async fn call_ucs_pre_authenticate_proxy(
external_vault_merchant_connector_account: payments_core::helpers::MerchantConnectorAccountType,
processor: &domain::Processor,
connector_enum: common_enums::connector_enums::Connector,
- execution_mode: common_enums::ExecutionMode,
+ rollout_settings: unified_connector_service::kill_switch::RolloutSettings,
) -> CustomResult<
Result<core_types::authentication::AuthenticationResponseData, core_types::ErrorResponse>,
ApiErrorResponse,
@@ -512,7 +520,7 @@ async fn call_ucs_pre_authenticate_proxy(
external_vault_merchant_connector_account,
processor,
connector_enum,
- execution_mode,
+ rollout_settings,
),
)
.await;
@@ -663,7 +671,7 @@ pub async fn perform_pre_authentication_proxy<F: Clone>(
)?;
let ProxyUcsGatewayContext {
- execution_mode,
+ rollout_settings,
session_state: updated_state,
platform: _,
external_vault_merchant_connector_account,
@@ -760,7 +768,7 @@ pub async fn perform_pre_authentication_proxy<F: Clone>(
external_vault_merchant_connector_account,
processor,
connector_enum,
- execution_mode,
+ rollout_settings,
)
.await?;
@@ -912,7 +920,7 @@ async fn call_ucs_post_authenticate_proxy<F: Clone>(
)?;
let Some(ProxyUcsGatewayContext {
- execution_mode,
+ rollout_settings,
session_state: updated_state,
platform,
external_vault_merchant_connector_account,
@@ -972,7 +980,7 @@ async fn call_ucs_post_authenticate_proxy<F: Clone>(
auth_merchant_connector_account,
external_vault_merchant_connector_account,
processor,
- execution_mode,
+ rollout_settings,
),
)
.await;
@@ -1383,7 +1391,7 @@ async fn call_ucs_authenticate_proxy(
)
});
- let (execution_path, updated_state) =
+ let (execution_path, updated_state, rollout_result) =
unified_connector_service::should_call_unified_connector_service(
state,
processor,
@@ -1465,7 +1473,13 @@ async fn call_ucs_authenticate_proxy(
auth_merchant_connector_account.clone(),
external_vault_merchant_connector_account,
processor,
- execution_mode,
+ unified_connector_service::kill_switch::RolloutSettings {
+ execution_mode,
+ kill_switch_enabled: rollout_result.kill_switch_enabled,
+ kill_switch_threshold: rollout_result.kill_switch_threshold,
+ connector_decline_threshold: rollout_result.connector_decline_threshold,
+ rollout_scope: rollout_result.rollout_scope.clone(),
+ },
Some(
payment_intent
.force_3ds_challenge
diff --git a/crates/router/src/core/fraud_check.rs b/crates/router/src/core/fraud_check.rs
index 9dc78a59cd..a4328d536e 100644
--- a/crates/router/src/core/fraud_check.rs
+++ b/crates/router/src/core/fraud_check.rs
@@ -187,20 +187,24 @@ where
// for which `decide_execution_path` returns UCS unconditionally and the kill
// switch is skipped — there is no direct integration to divert to.
// Everything else resolves to Direct.
- let execution_path = if is_pre_risk_evaluation {
- crate::core::unified_connector_service::should_call_unified_connector_service(
- state,
- platform.get_processor(),
- &router_data,
- None,
- payments::CallConnectorAction::Trigger,
- None,
- common_enums::TransactionType::Payment,
- )
- .await?
- .0
+ let (execution_path, rollout_result) = if is_pre_risk_evaluation {
+ let (execution_path, _updated_state, rollout_result) =
+ crate::core::unified_connector_service::should_call_unified_connector_service(
+ state,
+ platform.get_processor(),
+ &router_data,
+ None,
+ payments::CallConnectorAction::Trigger,
+ None,
+ common_enums::TransactionType::Payment,
+ )
+ .await?;
+ (execution_path, rollout_result)
} else {
- common_enums::ExecutionPath::Direct
+ (
+ common_enums::ExecutionPath::Direct,
+ payments::helpers::RolloutExecutionResult::default(),
+ )
};
let gateway_context = payments::gateway::context::RouterGatewayContext {
@@ -213,6 +217,10 @@ where
),
merchant_connector_account,
execution_path,
+ kill_switch_enabled: rollout_result.kill_switch_enabled,
+ kill_switch_threshold: rollout_result.kill_switch_threshold,
+ connector_decline_threshold: rollout_result.connector_decline_threshold,
+ rollout_scope: rollout_result.rollout_scope.clone(),
execution_mode: match execution_path {
common_enums::ExecutionPath::UnifiedConnectorService => {
common_enums::ExecutionMode::Primary
diff --git a/crates/router/src/core/fraud_check/gateway.rs b/crates/router/src/core/fraud_check/gateway.rs
index d07830da72..b06c1606b8 100644
--- a/crates/router/src/core/fraud_check/gateway.rs
+++ b/crates/router/src/core/fraud_check/gateway.rs
@@ -71,8 +71,8 @@ where
ConnectorError,
> {
let processor = &context.processor;
- let execution_mode = context.execution_mode;
+ let rollout_settings = context.rollout_settings();
let client = state
.grpc_client
.unified_connector_service_client
@@ -112,7 +112,9 @@ where
.attach_printable("Failed to construct request metadata")?;
let header_payload = state
- .get_grpc_headers_ucs(execution_mode)
+ .get_grpc_headers_ucs(rollout_settings.execution_mode)
+ .payment_method(Some(router_data.payment_method))
+ .payment_method_type(router_data.payment_method_type)
.external_vault_proxy_metadata(None)
.merchant_reference_id(None)
.resource_id(None)
@@ -123,7 +125,7 @@ where
state,
pre_risk_check_request,
header_payload,
- execution_mode,
+ rollout_settings,
|mut router_data, pre_risk_check_request, grpc_headers| async move {
let response = match Box::pin(client.frm_pre_risk_check(
pre_risk_check_request,
diff --git a/crates/router/src/core/payments.rs b/crates/router/src/core/payments.rs
index a08bf7d3f2..edc6a17ada 100644
--- a/crates/router/src/core/payments.rs
+++ b/crates/router/src/core/payments.rs
@@ -3529,7 +3529,7 @@ where
{
let previous_gateway = extract_gateway_system_from_payment_intent(payment_data);
- let (execution_path, updated_state) = should_call_unified_connector_service(
+ let (execution_path, updated_state, rollout_result) = should_call_unified_connector_service(
state,
platform.get_processor(),
&router_data,
@@ -3585,7 +3585,13 @@ where
&merchant_connector_account,
&external_vault_merchant_connector_account,
platform.get_processor(),
- execution_mode,
+ crate::core::unified_connector_service::kill_switch::RolloutSettings {
+ execution_mode,
+ kill_switch_enabled: rollout_result.kill_switch_enabled,
+ kill_switch_threshold: rollout_result.kill_switch_threshold,
+ connector_decline_threshold: rollout_result.connector_decline_threshold,
+ rollout_scope: rollout_result.rollout_scope.clone(),
+ },
)
.await?;
router_data
@@ -3607,6 +3613,10 @@ where
lineage_ids: lineage_ids.clone(),
merchant_connector_account: merchant_connector_account.clone(),
execution_path,
+ kill_switch_enabled: rollout_result.kill_switch_enabled,
+ kill_switch_threshold: rollout_result.kill_switch_threshold,
+ connector_decline_threshold: rollout_result.connector_decline_threshold,
+ rollout_scope: rollout_result.rollout_scope.clone(),
execution_mode,
},
)
@@ -3625,6 +3635,10 @@ where
lineage_ids,
merchant_connector_account: merchant_connector_account.clone(),
execution_path,
+ kill_switch_enabled: rollout_result.kill_switch_enabled,
+ kill_switch_threshold: rollout_result.kill_switch_threshold,
+ connector_decline_threshold: rollout_result.connector_decline_threshold,
+ rollout_scope: rollout_result.rollout_scope.clone(),
execution_mode,
};
@@ -6365,7 +6379,7 @@ where
// Extract previous gateway from payment data
let previous_gateway = extract_gateway_system_from_payment_intent(payment_data);
- let (execution_path, updated_state) = should_call_unified_connector_service(
+ let (execution_path, updated_state, rollout_result) = should_call_unified_connector_service(
state,
processor,
&router_data,
@@ -6395,6 +6409,10 @@ where
lineage_ids,
merchant_connector_account: merchant_connector_account.clone(),
execution_path,
+ kill_switch_enabled: rollout_result.kill_switch_enabled,
+ kill_switch_threshold: rollout_result.kill_switch_threshold,
+ connector_decline_threshold: rollout_result.connector_decline_threshold,
+ rollout_scope: rollout_result.rollout_scope.clone(),
execution_mode,
};
@@ -6956,7 +6974,7 @@ where
let previous_gateway = extract_gateway_system_from_payment_intent(payment_data);
// do order creation
- let (execution_path, updated_state) = should_call_unified_connector_service(
+ let (execution_path, updated_state, rollout_result) = should_call_unified_connector_service(
state,
platform.get_processor(),
&router_data,
@@ -6986,6 +7004,10 @@ where
lineage_ids,
merchant_connector_account: merchant_connector_account_type_details.clone(),
execution_path,
+ kill_switch_enabled: rollout_result.kill_switch_enabled,
+ kill_switch_threshold: rollout_result.kill_switch_threshold,
+ connector_decline_threshold: rollout_result.connector_decline_threshold,
+ rollout_scope: rollout_result.rollout_scope.clone(),
execution_mode,
};
@@ -7088,16 +7110,17 @@ where
// Extract previous gateway from payment data
let previous_gateway = extract_gateway_system_from_payment_intent(payment_data);
- let (execution_path, updated_state) = should_call_unified_connector_service(
- state,
- processor,
- &router_data,
- previous_gateway,
- call_connector_action.clone(),
- None,
- common_enums::TransactionType::Payment,
- )
- .await?;
+ let (execution_path, updated_state, rollout_result) =
+ should_call_unified_connector_service(
+ state,
+ processor,
+ &router_data,
+ previous_gateway,
+ call_connector_action.clone(),
+ None,
+ common_enums::TransactionType::Payment,
+ )
+ .await?;
let lineage_ids = grpc_client::LineageIds::new(
business_profile.merchant_id.clone(),
business_profile.get_id().clone(),
@@ -7117,6 +7140,10 @@ where
lineage_ids,
merchant_connector_account: merchant_connector_account_type_details.clone(),
execution_path,
+ kill_switch_enabled: rollout_result.kill_switch_enabled,
+ kill_switch_threshold: rollout_result.kill_switch_threshold,
+ connector_decline_threshold: rollout_result.connector_decline_threshold,
+ rollout_scope: rollout_result.rollout_scope.clone(),
execution_mode,
};
let call_connector_service_response = call_connector_service(
@@ -7201,7 +7228,10 @@ where
merchant_connector_account_type_details.clone(),
external_vault_merchant_connector_account_type_details.clone(),
processor,
- ExecutionMode::Primary, //UCS is called in primary mode
+ // No rollout config governs the external-vault proxy path, so nothing can divert it.
+ crate::core::unified_connector_service::kill_switch::RolloutSettings::without_kill_switch(
+ ExecutionMode::Primary,
+ ),
)
.await?;
@@ -7284,7 +7314,7 @@ where
)
.await?;
- let (execution_path, updated_state) = should_call_unified_connector_service(
+ let (execution_path, updated_state, rollout_result) = should_call_unified_connector_service(
state,
platform.get_processor(),
&router_data,
@@ -7314,6 +7344,10 @@ where
lineage_ids,
merchant_connector_account: merchant_connector_account.clone(),
execution_path,
+ kill_switch_enabled: rollout_result.kill_switch_enabled,
+ kill_switch_threshold: rollout_result.kill_switch_threshold,
+ connector_decline_threshold: rollout_result.connector_decline_threshold,
+ rollout_scope: rollout_result.rollout_scope.clone(),
execution_mode,
};
@@ -8386,7 +8420,7 @@ where
dyn api::Connector:
services::api::ConnectorIntegration<F, RouterDReq, router_types::PaymentsResponseData>,
{
- let (execution_path, updated_state) = should_call_unified_connector_service(
+ let (execution_path, updated_state, rollout_result) = should_call_unified_connector_service(
state,
processor,
&router_data,
@@ -8416,6 +8450,10 @@ where
lineage_ids,
merchant_connector_account: merchant_connector_account.clone(),
execution_path,
+ kill_switch_enabled: rollout_result.kill_switch_enabled,
+ kill_switch_threshold: rollout_result.kill_switch_threshold,
+ connector_decline_threshold: rollout_result.connector_decline_threshold,
+ rollout_scope: rollout_result.rollout_scope.clone(),
execution_mode,
};
diff --git a/crates/router/src/core/payments/access_token.rs b/crates/router/src/core/payments/access_token.rs
index 92b0ec4e00..9e6a57cde4 100644
--- a/crates/router/src/core/payments/access_token.rs
+++ b/crates/router/src/core/payments/access_token.rs
@@ -383,6 +383,8 @@ async fn fetch_access_token_from_ucs(
let grpc_headers = state
.get_grpc_headers_ucs(common_enums::ExecutionMode::Primary)
+ .payment_method(None)
+ .payment_method_type(None)
.external_vault_proxy_metadata(None)
.merchant_reference_id(None)
.resource_id(None)
diff --git a/crates/router/src/core/payments/flows.rs b/crates/router/src/core/payments/flows.rs
index b3fc4813c7..0a9c77ae27 100644
--- a/crates/router/src/core/payments/flows.rs
+++ b/crates/router/src/core/payments/flows.rs
@@ -328,7 +328,7 @@ pub trait Feature<F, T> {
_merchant_connector_account: domain::MerchantConnectorAccountTypeDetails,
_external_vault_merchant_connector_account: domain::MerchantConnectorAccountTypeDetails,
_processor: &domain::Processor,
- _unified_connector_service_execution_mode: common_enums::ExecutionMode,
+ _rollout_settings: crate::core::unified_connector_service::kill_switch::RolloutSettings,
) -> RouterResult<()>
where
F: Clone,
@@ -347,7 +347,7 @@ pub trait Feature<F, T> {
_merchant_connector_account: &'a helpers::MerchantConnectorAccountType,
_external_vault_merchant_connector_account: &'a helpers::MerchantConnectorAccountType,
_processor: &domain::Processor,
- _unified_connector_service_execution_mode: common_enums::ExecutionMode,
+ _rollout_settings: crate::core::unified_connector_service::kill_switch::RolloutSettings,
) -> RouterResult<()>
where
F: Clone,
diff --git a/crates/router/src/core/payments/flows/authorize_flow.rs b/crates/router/src/core/payments/flows/authorize_flow.rs
index 7eefce8a7d..4d27dcdc2d 100644
--- a/crates/router/src/core/payments/flows/authorize_flow.rs
+++ b/crates/router/src/core/payments/flows/authorize_flow.rs
@@ -1624,7 +1624,7 @@ pub async fn call_unified_connector_service_pre_authenticate(
#[cfg(feature = "v2")] merchant_connector_account: domain::MerchantConnectorAccountTypeDetails,
processor: &domain::Processor,
connector: enums::connector_enums::Connector,
- unified_connector_service_execution_mode: enums::ExecutionMode,
+ rollout_settings: unified_connector_service::kill_switch::RolloutSettings,
) -> errors::CustomResult<
(
types::RouterData<
@@ -1672,7 +1672,9 @@ pub async fn call_unified_connector_service_pre_authenticate(
.ok()
.map(ucs_types::UcsResourceId::PaymentAttempt);
let headers_builder = state
- .get_grpc_headers_ucs(unified_connector_service_execution_mode)
+ .get_grpc_headers_ucs(rollout_settings.execution_mode)
+ .payment_method(Some(router_data.payment_method))
+ .payment_method_type(router_data.payment_method_type)
.external_vault_proxy_metadata(None)
.merchant_reference_id(merchant_reference_id)
.resource_id(resource_id)
@@ -1682,7 +1684,7 @@ pub async fn call_unified_connector_service_pre_authenticate(
state,
payment_pre_authenticate_request,
headers_builder,
- unified_connector_service_execution_mode,
+ rollout_settings,
|mut router_data, payment_pre_authenticate_request, grpc_headers| async move {
let response = client
.payment_pre_authenticate(
@@ -1752,7 +1754,7 @@ pub async fn call_unified_connector_service_pre_authenticate_proxy(
external_vault_merchant_connector_account: helpers::MerchantConnectorAccountType,
processor: &domain::Processor,
connector: enums::connector_enums::Connector,
- unified_connector_service_execution_mode: enums::ExecutionMode,
+ rollout_settings: unified_connector_service::kill_switch::RolloutSettings,
) -> errors::CustomResult<
types::RouterData<
api::PreAuthenticate,
@@ -1818,7 +1820,9 @@ pub async fn call_unified_connector_service_pre_authenticate_proxy(
.ok()
.map(ucs_types::UcsResourceId::PaymentAttempt);
let headers_builder = state
- .get_grpc_headers_ucs(unified_connector_service_execution_mode)
+ .get_grpc_headers_ucs(rollout_settings.execution_mode)
+ .payment_method(Some(router_data.payment_method))
+ .payment_method_type(router_data.payment_method_type)
.external_vault_proxy_metadata(Some(external_vault_proxy_metadata))
.merchant_reference_id(merchant_reference_id)
.resource_id(resource_id)
@@ -1829,7 +1833,7 @@ pub async fn call_unified_connector_service_pre_authenticate_proxy(
state,
payment_pre_authenticate_request,
headers_builder,
- unified_connector_service_execution_mode,
+ rollout_settings,
|mut router_data, payment_pre_authenticate_request, grpc_headers| async move {
let response = Box::pin(client.payment_pre_authenticate(
payment_pre_authenticate_request,
diff --git a/crates/router/src/core/payments/flows/complete_authorize_flow.rs b/crates/router/src/core/payments/flows/complete_authorize_flow.rs
index b85664d1e0..a870c126f9 100644
--- a/crates/router/src/core/payments/flows/complete_authorize_flow.rs
+++ b/crates/router/src/core/payments/flows/complete_authorize_flow.rs
@@ -768,7 +768,7 @@ pub async fn call_unified_connector_service_authenticate(
#[cfg(feature = "v2")] merchant_connector_account: domain::MerchantConnectorAccountTypeDetails,
processor: &domain::Processor,
connector: connector_enums::Connector,
- unified_connector_service_execution_mode: common_enums::ExecutionMode,
+ rollout_settings: crate::core::unified_connector_service::kill_switch::RolloutSettings,
) -> errors::CustomResult<
types::RouterData<
api::Authenticate,
@@ -812,7 +812,9 @@ pub async fn call_unified_connector_service_authenticate(
.ok()
.map(ucs_types::UcsResourceId::PaymentAttempt);
let headers_builder = state
- .get_grpc_headers_ucs(unified_connector_service_execution_mode)
+ .get_grpc_headers_ucs(rollout_settings.execution_mode)
+ .payment_method(Some(router_data.payment_method))
+ .payment_method_type(router_data.payment_method_type)
.external_vault_proxy_metadata(None)
.merchant_reference_id(merchant_reference_id)
.resource_id(resource_id)
@@ -822,7 +824,7 @@ pub async fn call_unified_connector_service_authenticate(
state,
payment_authenticate_request,
headers_builder,
- unified_connector_service_execution_mode,
+ rollout_settings,
|mut router_data, payment_authenticate_request, grpc_headers| async move {
let response = Box::pin(client.payment_authenticate(
payment_authenticate_request,
@@ -895,7 +897,7 @@ pub async fn call_unified_connector_service_authenticate_proxy(
merchant_connector_account: helpers::MerchantConnectorAccountType,
external_vault_merchant_connector_account: helpers::MerchantConnectorAccountType,
processor: &domain::Processor,
- unified_connector_service_execution_mode: common_enums::ExecutionMode,
+ rollout_settings: crate::core::unified_connector_service::kill_switch::RolloutSettings,
force_3ds_challenge: Option<bool>,
notification_url: Option<common_utils::types::Url>,
acquirer_metadata: Option<serde_json::Value>,
@@ -972,7 +974,9 @@ pub async fn call_unified_connector_service_authenticate_proxy(
.ok()
.map(ucs_types::UcsResourceId::PaymentAttempt);
let headers_builder = state
- .get_grpc_headers_ucs(unified_connector_service_execution_mode)
+ .get_grpc_headers_ucs(rollout_settings.execution_mode)
+ .payment_method(Some(router_data.payment_method))
+ .payment_method_type(router_data.payment_method_type)
.external_vault_proxy_metadata(Some(external_vault_proxy_metadata))
.merchant_reference_id(merchant_reference_id)
.resource_id(resource_id)
@@ -982,7 +986,7 @@ pub async fn call_unified_connector_service_authenticate_proxy(
state,
payment_authenticate_request,
headers_builder,
- unified_connector_service_execution_mode,
+ rollout_settings,
|mut router_data, payment_authenticate_request, grpc_headers| async move {
let response = Box::pin(client.payment_authenticate(
payment_authenticate_request,
@@ -1034,7 +1038,7 @@ pub async fn call_unified_connector_service_post_authenticate(
#[cfg(feature = "v1")] merchant_connector_account: helpers::MerchantConnectorAccountType,
#[cfg(feature = "v2")] merchant_connector_account: domain::MerchantConnectorAccountTypeDetails,
processor: &domain::Processor,
- unified_connector_service_execution_mode: common_enums::ExecutionMode,
+ rollout_settings: crate::core::unified_connector_service::kill_switch::RolloutSettings,
) -> errors::CustomResult<
types::RouterData<
api::PostAuthenticate,
@@ -1078,7 +1082,9 @@ pub async fn call_unified_connector_service_post_authenticate(
.ok()
.map(ucs_types::UcsResourceId::PaymentAttempt);
let headers_builder = state
- .get_grpc_headers_ucs(unified_connector_service_execution_mode)
+ .get_grpc_headers_ucs(rollout_settings.execution_mode)
+ .payment_method(Some(router_data.payment_method))
+ .payment_method_type(router_data.payment_method_type)
.external_vault_proxy_metadata(None)
.merchant_reference_id(merchant_reference_id)
.resource_id(resource_id)
@@ -1088,7 +1094,7 @@ pub async fn call_unified_connector_service_post_authenticate(
state,
payment_post_authenticate_request,
headers_builder,
- unified_connector_service_execution_mode,
+ rollout_settings,
|mut router_data, payment_post_authenticate_request, grpc_headers| async move {
let response = Box::pin(client.payment_post_authenticate(
payment_post_authenticate_request,
@@ -1157,7 +1163,7 @@ pub async fn call_unified_connector_service_post_authenticate_proxy(
merchant_connector_account: helpers::MerchantConnectorAccountType,
external_vault_merchant_connector_account: helpers::MerchantConnectorAccountType,
processor: &domain::Processor,
- unified_connector_service_execution_mode: common_enums::ExecutionMode,
+ rollout_settings: crate::core::unified_connector_service::kill_switch::RolloutSettings,
) -> errors::CustomResult<
types::RouterData<
api::PostAuthenticate,
@@ -1222,7 +1228,9 @@ pub async fn call_unified_connector_service_post_authenticate_proxy(
.ok()
.map(ucs_types::UcsResourceId::PaymentAttempt);
let headers_builder = state
- .get_grpc_headers_ucs(unified_connector_service_execution_mode)
+ .get_grpc_headers_ucs(rollout_settings.execution_mode)
+ .payment_method(Some(router_data.payment_method))
+ .payment_method_type(router_data.payment_method_type)
.external_vault_proxy_metadata(Some(external_vault_proxy_metadata))
.merchant_reference_id(merchant_reference_id)
.resource_id(resource_id)
@@ -1232,7 +1240,7 @@ pub async fn call_unified_connector_service_post_authenticate_proxy(
state,
payment_post_authenticate_request,
headers_builder,
- unified_connector_service_execution_mode,
+ rollout_settings,
|mut router_data, payment_post_authenticate_request, grpc_headers| async move {
let response = Box::pin(client.payment_post_authenticate(
payment_post_authenticate_request,
diff --git a/crates/router/src/core/payments/flows/external_proxy_flow.rs b/crates/router/src/core/payments/flows/external_proxy_flow.rs
index 1a67db272a..432098a320 100644
--- a/crates/router/src/core/payments/flows/external_proxy_flow.rs
+++ b/crates/router/src/core/payments/flows/external_proxy_flow.rs
@@ -407,7 +407,7 @@ impl Feature<api::ExternalVaultProxy, types::ExternalVaultProxyPaymentsData>
merchant_connector_account: domain::MerchantConnectorAccountTypeDetails,
external_vault_merchant_connector_account: domain::MerchantConnectorAccountTypeDetails,
processor: &domain::Processor,
- unified_connector_service_execution_mode: enums::ExecutionMode,
+ rollout_settings: unified_connector_service::kill_switch::RolloutSettings,
) -> RouterResult<()> {
let client = state
.grpc_client
@@ -453,7 +453,9 @@ impl Feature<api::ExternalVaultProxy, types::ExternalVaultProxyPaymentsData>
.map(ucs_types::UcsResourceId::PaymentAttempt);
let headers_builder = state
- .get_grpc_headers_ucs(unified_connector_service_execution_mode)
+ .get_grpc_headers_ucs(rollout_settings.execution_mode)
+ .payment_method(Some(self.payment_method))
+ .payment_method_type(self.payment_method_type)
.external_vault_proxy_metadata(Some(external_vault_proxy_metadata))
.merchant_reference_id(merchant_reference_id)
.resource_id(resource_id)
@@ -463,7 +465,7 @@ impl Feature<api::ExternalVaultProxy, types::ExternalVaultProxyPaymentsData>
state,
payment_authorize_request.clone(),
headers_builder,
- unified_connector_service_execution_mode,
+ rollout_settings,
|mut router_data, payment_authorize_request, grpc_headers| async move {
// UCS connector errors are handled by the wrapper — see `ucs_logging_wrapper`.
let response = Box::pin(client
@@ -521,7 +523,7 @@ impl Feature<api::ExternalVaultProxy, types::ExternalVaultProxyPaymentsData>
merchant_connector_account: &'a helpers::MerchantConnectorAccountType,
external_vault_merchant_connector_account: &'a helpers::MerchantConnectorAccountType,
processor: &domain::Processor,
- unified_connector_service_execution_mode: enums::ExecutionMode,
+ rollout_settings: unified_connector_service::kill_switch::RolloutSettings,
) -> RouterResult<()> {
let client = state
.grpc_client
@@ -568,7 +570,9 @@ impl Feature<api::ExternalVaultProxy, types::ExternalVaultProxyPaymentsData>
.map(ucs_types::UcsResourceId::PaymentAttempt);
let headers_builder = state
- .get_grpc_headers_ucs(unified_connector_service_execution_mode)
+ .get_grpc_headers_ucs(rollout_settings.execution_mode)
+ .payment_method(Some(self.payment_method))
+ .payment_method_type(self.payment_method_type)
.external_vault_proxy_metadata(Some(external_vault_proxy_metadata))
.merchant_reference_id(merchant_reference_id)
.resource_id(resource_id)
@@ -579,7 +583,7 @@ impl Feature<api::ExternalVaultProxy, types::ExternalVaultProxyPaymentsData>
state,
payment_authorize_request.clone(),
headers_builder,
- unified_connector_service_execution_mode,
+ rollout_settings,
|mut router_data, payment_authorize_request, grpc_headers| async move {
// UCS connector errors are handled by the wrapper — see `ucs_logging_wrapper`.
let response = Box::pin(client
diff --git a/crates/router/src/core/payments/gateway/access_token_gateway.rs b/crates/router/src/core/payments/gateway/access_token_gateway.rs
index 95a11843df..545bc777b1 100644
--- a/crates/router/src/core/payments/gateway/access_token_gateway.rs
+++ b/crates/router/src/core/payments/gateway/access_token_gateway.rs
@@ -74,11 +74,11 @@ where
>,
ConnectorError,
> {
+ let rollout_settings = context.rollout_settings();
let merchant_connector_account = context.merchant_connector_account;
let processor = &context.processor;
let lineage_ids = context.lineage_ids;
let header_payload = context.header_payload;
- let unified_connector_service_execution_mode = context.execution_mode;
let client = state
.grpc_client
@@ -188,7 +188,9 @@ where
};
let header_payload = state
- .get_grpc_headers_ucs(unified_connector_service_execution_mode)
+ .get_grpc_headers_ucs(rollout_settings.execution_mode)
+ .payment_method(Some(router_data.payment_method))
+ .payment_method_type(router_data.payment_method_type)
.external_vault_proxy_metadata(None)
.merchant_reference_id(merchant_reference_id)
.resource_id(resource_id)
@@ -199,7 +201,7 @@ where
state,
create_access_token_request,
header_payload,
- unified_connector_service_execution_mode,
+ rollout_settings,
|mut router_data, create_access_token_request, grpc_headers| async move {
let response = match client
.create_access_token(
diff --git a/crates/router/src/core/payments/gateway/authenticate_gateway.rs b/crates/router/src/core/payments/gateway/authenticate_gateway.rs
index 82da6c1999..dece489b2e 100644
--- a/crates/router/src/core/payments/gateway/authenticate_gateway.rs
+++ b/crates/router/src/core/payments/gateway/authenticate_gateway.rs
@@ -62,11 +62,11 @@ where
RouterData<Self, types::PaymentsAuthenticateData, types::PaymentsResponseData>,
ConnectorError,
> {
+ let rollout_settings = context.rollout_settings();
let merchant_connector_account = context.merchant_connector_account;
let processor = &context.processor;
let lineage_ids = context.lineage_ids;
let header_payload = context.header_payload;
- let unified_connector_service_execution_mode = context.execution_mode;
let connector_enum =
common_enums::connector_enums::Connector::from_str(&router_data.connector)
.change_context(ConnectorError::InvalidConnectorName)
@@ -79,7 +79,7 @@ where
merchant_connector_account,
processor,
connector_enum,
- unified_connector_service_execution_mode,
+ rollout_settings,
)
.await
}
diff --git a/crates/router/src/core/payments/gateway/authorize_gateway.rs b/crates/router/src/core/payments/gateway/authorize_gateway.rs
index 25d363e217..80f69966d1 100644
--- a/crates/router/src/core/payments/gateway/authorize_gateway.rs
+++ b/crates/router/src/core/payments/gateway/authorize_gateway.rs
@@ -70,11 +70,11 @@ where
RouterData<Self, types::PaymentsAuthorizeData, types::PaymentsResponseData>,
ConnectorError,
> {
+ let rollout_settings = context.rollout_settings();
let merchant_connector_account = context.merchant_connector_account;
let processor = &context.processor;
let lineage_ids = context.lineage_ids;
let header_payload = context.header_payload;
- let unified_connector_service_execution_mode = context.execution_mode;
let client = state
.grpc_client
.unified_connector_service_client
@@ -113,7 +113,9 @@ where
.map(ucs_types::UcsResourceId::PaymentAttempt);
let grpc_headers = state
- .get_grpc_headers_ucs(unified_connector_service_execution_mode)
+ .get_grpc_headers_ucs(rollout_settings.execution_mode)
+ .payment_method(Some(router_data.payment_method))
+ .payment_method_type(router_data.payment_method_type)
.external_vault_proxy_metadata(None)
.merchant_reference_id(merchant_reference_id)
.resource_id(resource_id)
@@ -134,7 +136,7 @@ where
state,
recurring_payment_charge_request,
grpc_headers,
- unified_connector_service_execution_mode,
+ rollout_settings,
|mut router_data, recurring_payment_charge_request, grpc_headers| async move {
let response = match Box::pin(client.recurring_payment_charge(
recurring_payment_charge_request,
@@ -217,7 +219,7 @@ where
state,
granular_authorize_request,
grpc_headers,
- unified_connector_service_execution_mode,
+ rollout_settings,
|mut router_data, granular_authorize_request, grpc_headers| async move {
let response = match Box::pin(client.payment_authorize(
granular_authorize_request,
diff --git a/crates/router/src/core/payments/gateway/cancel_gateway.rs b/crates/router/src/core/payments/gateway/cancel_gateway.rs
index a386b96258..4379ebc698 100644
--- a/crates/router/src/core/payments/gateway/cancel_gateway.rs
+++ b/crates/router/src/core/payments/gateway/cancel_gateway.rs
@@ -59,11 +59,11 @@ where
RouterData<Self, types::PaymentsCancelData, types::PaymentsResponseData>,
ConnectorError,
> {
+ let rollout_settings = context.rollout_settings();
let merchant_connector_account = context.merchant_connector_account;
let processor = &context.processor;
let lineage_ids = context.lineage_ids;
let header_payload = context.header_payload;
- let unified_connector_service_execution_mode = context.execution_mode;
let client = state
.grpc_client
.unified_connector_service_client
@@ -101,7 +101,9 @@ where
.map(ucs_types::UcsResourceId::PaymentAttempt);
let header_payload = state
- .get_grpc_headers_ucs(unified_connector_service_execution_mode)
+ .get_grpc_headers_ucs(rollout_settings.execution_mode)
+ .payment_method(Some(router_data.payment_method))
+ .payment_method_type(router_data.payment_method_type)
.external_vault_proxy_metadata(None)
.merchant_reference_id(merchant_reference_id)
.resource_id(resource_id)
@@ -112,7 +114,7 @@ where
state,
payment_void_request,
header_payload,
- unified_connector_service_execution_mode,
+ rollout_settings,
|mut router_data, payment_void_request, grpc_headers| async move {
let response = match client
.payment_void(payment_void_request, connector_auth_metadata, grpc_headers)
diff --git a/crates/router/src/core/payments/gateway/capture_gateway.rs b/crates/router/src/core/payments/gateway/capture_gateway.rs
index 48cc70502a..32fd7716dd 100644
--- a/crates/router/src/core/payments/gateway/capture_gateway.rs
+++ b/crates/router/src/core/payments/gateway/capture_gateway.rs
@@ -59,11 +59,11 @@ where
RouterData<Self, types::PaymentsCaptureData, types::PaymentsResponseData>,
ConnectorError,
> {
+ let rollout_settings = context.rollout_settings();
let merchant_connector_account = context.merchant_connector_account;
let processor = &context.processor;
let lineage_ids = context.lineage_ids;
let header_payload = context.header_payload;
- let unified_connector_service_execution_mode = context.execution_mode;
let client = state
.grpc_client
.unified_connector_service_client
@@ -100,7 +100,9 @@ where
.map(ucs_types::UcsResourceId::PaymentAttempt);
let header_payload = state
- .get_grpc_headers_ucs(unified_connector_service_execution_mode)
+ .get_grpc_headers_ucs(rollout_settings.execution_mode)
+ .payment_method(Some(router_data.payment_method))
+ .payment_method_type(router_data.payment_method_type)
.external_vault_proxy_metadata(None)
.merchant_reference_id(merchant_reference_id)
.resource_id(resource_id)
@@ -110,7 +112,7 @@ where
state,
payment_capture_request,
header_payload,
- unified_connector_service_execution_mode,
+ rollout_settings,
|mut router_data, payment_capture_request, grpc_headers| async move {
let response = match client
.payment_capture(
diff --git a/crates/router/src/core/payments/gateway/complete_authorize_gateway.rs b/crates/router/src/core/payments/gateway/complete_authorize_gateway.rs
index 926be9e1a8..ab59267729 100644
--- a/crates/router/src/core/payments/gateway/complete_authorize_gateway.rs
+++ b/crates/router/src/core/payments/gateway/complete_authorize_gateway.rs
@@ -63,11 +63,11 @@ where
RouterData<Self, types::CompleteAuthorizeData, types::PaymentsResponseData>,
ConnectorError,
> {
+ let rollout_settings = context.rollout_settings();
let merchant_connector_account = context.merchant_connector_account;
let processor = &context.processor;
let lineage_ids = context.lineage_ids;
let header_payload = context.header_payload;
- let unified_connector_service_execution_mode = context.execution_mode;
let client = state
.grpc_client
.unified_connector_service_client
@@ -105,7 +105,9 @@ where
.ok()
.map(ucs_types::UcsResourceId::PaymentAttempt);
let header_payload = state
- .get_grpc_headers_ucs(unified_connector_service_execution_mode)
+ .get_grpc_headers_ucs(rollout_settings.execution_mode)
+ .payment_method(Some(router_data.payment_method))
+ .payment_method_type(router_data.payment_method_type)
.external_vault_proxy_metadata(None)
.merchant_reference_id(merchant_reference_id)
.resource_id(resource_id)
@@ -115,7 +117,7 @@ where
state,
granular_authorize_request,
header_payload,
- unified_connector_service_execution_mode,
+ rollout_settings,
|mut router_data, granular_authorize_request, grpc_headers| async move {
let response = match Box::pin(client.payment_authorize(
granular_authorize_request,
diff --git a/crates/router/src/core/payments/gateway/context.rs b/crates/router/src/core/payments/gateway/context.rs
index 9cfc19ad5f..d3e38f1295 100644
--- a/crates/router/src/core/payments/gateway/context.rs
+++ b/crates/router/src/core/payments/gateway/context.rs
@@ -7,7 +7,7 @@
use common_enums::{ExecutionMode, ExecutionPath, GatewaySystem};
use common_utils::id_type;
use external_services::grpc_client::LineageIds;
-use hyperswitch_domain_models::{business_profile, payments::HeaderPayload, platform::Processor};
+use hyperswitch_domain_models::{payments::HeaderPayload, platform::Processor};
use hyperswitch_interfaces::api::gateway::GatewayContext;
use crate::core::payments::helpers;
@@ -42,39 +42,36 @@ pub struct RouterGatewayContext {
/// Execution path (Direct, UCS, or Shadow)
pub execution_path: ExecutionPath,
+
+ /// Kill switch thresholds for this scope, read once by the gate. Carried so a failure
+ /// is counted against the same threshold the gate used, rather than re-reading the
+ /// config later and risking a different answer.
+ pub kill_switch_enabled: bool,
+ pub kill_switch_threshold: u64,
+ /// `None` means connector declines never trip this scope.
+ pub connector_decline_threshold: Option<u64>,
+ /// The scope the gate decided under. Carried so the flows that inherit this context
+ /// without gating for themselves count against the scope that authorised them.
+ pub rollout_scope: Option<String>,
}
-impl RouterGatewayContext {
- pub fn new(
- processor: Processor,
- header_payload: HeaderPayload,
- business_profile: &business_profile::Profile,
- #[cfg(feature = "v1")] merchant_connector_account: helpers::MerchantConnectorAccountType,
- #[cfg(feature = "v2")]
- merchant_connector_account: hyperswitch_domain_models::merchant_connector_account::MerchantConnectorAccountTypeDetails,
- execution_path: ExecutionPath,
- creds_identifier: Option<String>,
- ) -> Self {
- let lineage_ids = LineageIds::new(
- business_profile.merchant_id.clone(),
- business_profile.get_id().clone(),
- );
- let execution_mode = match execution_path {
- ExecutionPath::UnifiedConnectorService => ExecutionMode::Primary,
- ExecutionPath::ShadowUnifiedConnectorService => ExecutionMode::Shadow,
- // ExecutionMode is irrelevant for Direct path in this context
- ExecutionPath::Direct => ExecutionMode::NotApplicable,
- };
- Self {
- processor,
- header_payload,
- lineage_ids,
- merchant_connector_account,
- execution_mode,
- execution_path,
- creds_identifier,
- }
+/// Implementation of GatewayContext trait for RouterGatewayContext
+///
+/// This allows the framework to extract execution metadata without knowing
+/// the concrete structure of RouterGatewayContext.
+impl GatewayContext for RouterGatewayContext {
+ fn execution_path(&self) -> ExecutionPath {
+ self.execution_path
}
+
+ /// Get the execution mode (Primary, Shadow, etc.)
+ fn execution_mode(&self) -> ExecutionMode {
+ self.execution_mode
+ }
+}
+impl RouterGatewayContext {
+ /// Context for the Direct path, which never calls UCS and so never trips the kill
+ /// switch; the thresholds are inert here.
pub fn direct(
processor: Processor,
#[cfg(feature = "v1")] merchant_connector_account: helpers::MerchantConnectorAccountType,
@@ -93,26 +90,28 @@ impl RouterGatewayContext {
execution_mode: ExecutionMode::NotApplicable,
execution_path: ExecutionPath::Direct,
creds_identifier,
+ kill_switch_enabled: false,
+ kill_switch_threshold: 1,
+ connector_decline_threshold: None,
+ // The direct path is not gated, so no scope decided it.
+ rollout_scope: None,
}
}
-}
-/// Implementation of GatewayContext trait for RouterGatewayContext
-///
-/// This allows the framework to extract execution metadata without knowing
-/// the concrete structure of RouterGatewayContext.
-impl GatewayContext for RouterGatewayContext {
- fn execution_path(&self) -> ExecutionPath {
- self.execution_path
+ /// Get the gateway system (Direct, UnifiedConnectorService, etc.)
+ /// The kill switch settings this request resolved, for the UCS logging wrappers.
+ pub fn rollout_settings(
+ &self,
+ ) -> crate::core::unified_connector_service::kill_switch::RolloutSettings {
+ crate::core::unified_connector_service::kill_switch::RolloutSettings {
+ execution_mode: self.execution_mode,
+ kill_switch_enabled: self.kill_switch_enabled,
+ kill_switch_threshold: self.kill_switch_threshold,
+ connector_decline_threshold: self.connector_decline_threshold,
+ rollout_scope: self.rollout_scope.clone(),
+ }
}
- /// Get the execution mode (Primary, Shadow, etc.)
- fn execution_mode(&self) -> ExecutionMode {
- self.execution_mode
- }
-}
-impl RouterGatewayContext {
- /// Get the gateway system (Direct, UnifiedConnectorService, etc.)
pub fn get_gateway_system(&self) -> GatewaySystem {
match self.execution_path {
ExecutionPath::Direct => GatewaySystem::Direct,
diff --git a/crates/router/src/core/payments/gateway/create_customer_gateway.rs b/crates/router/src/core/payments/gateway/create_customer_gateway.rs
index b75d512df2..3f8d2280f9 100644
--- a/crates/router/src/core/payments/gateway/create_customer_gateway.rs
+++ b/crates/router/src/core/payments/gateway/create_customer_gateway.rs
@@ -68,11 +68,11 @@ where
let connector_name = router_data.connector.clone();
let _connector_enum = common_enums::connector_enums::Connector::from_str(&connector_name)
.change_context(ConnectorError::InvalidConnectorName)?;
+ let rollout_settings = context.rollout_settings();
let merchant_connector_account = context.merchant_connector_account;
let processor = &context.processor;
let lineage_ids = context.lineage_ids;
let header_payload = context.header_payload;
- let unified_connector_service_execution_mode = context.execution_mode;
let client = state
.grpc_client
@@ -113,7 +113,9 @@ where
.map(ucs_types::UcsResourceId::PaymentAttempt);
let grpc_headers = state
- .get_grpc_headers_ucs(unified_connector_service_execution_mode)
+ .get_grpc_headers_ucs(rollout_settings.execution_mode)
+ .payment_method(Some(router_data.payment_method))
+ .payment_method_type(router_data.payment_method_type)
.external_vault_proxy_metadata(None)
.merchant_reference_id(merchant_reference_id)
.resource_id(resource_id)
@@ -123,7 +125,7 @@ where
state,
create_connector_customer_request,
grpc_headers,
- unified_connector_service_execution_mode,
+ rollout_settings,
|mut router_data, create_connector_customer_request, grpc_headers| async move {
let response = match Box::pin(client.create_connector_customer(
create_connector_customer_request,
diff --git a/crates/router/src/core/payments/gateway/create_order_gateway.rs b/crates/router/src/core/payments/gateway/create_order_gateway.rs
index 133741f532..8120fabd3a 100644
--- a/crates/router/src/core/payments/gateway/create_order_gateway.rs
+++ b/crates/router/src/core/payments/gateway/create_order_gateway.rs
@@ -64,11 +64,11 @@ where
RouterData<Self, types::CreateOrderRequestData, types::PaymentsResponseData>,
ConnectorError,
> {
+ let rollout_settings = context.rollout_settings();
let merchant_connector_account = context.merchant_connector_account;
let processor = &context.processor;
let lineage_ids = context.lineage_ids;
let header_payload = context.header_payload;
- let unified_connector_service_execution_mode = context.execution_mode;
let client = state
.grpc_client
.unified_connector_service_client
@@ -105,7 +105,9 @@ where
.map(ucs_types::UcsResourceId::PaymentAttempt);
let header_payload = state
- .get_grpc_headers_ucs(unified_connector_service_execution_mode)
+ .get_grpc_headers_ucs(rollout_settings.execution_mode)
+ .payment_method(Some(router_data.payment_method))
+ .payment_method_type(router_data.payment_method_type)
.external_vault_proxy_metadata(None)
.merchant_reference_id(merchant_reference_id)
.resource_id(resource_id)
@@ -115,7 +117,7 @@ where
state,
create_order_request,
header_payload,
- unified_connector_service_execution_mode,
+ rollout_settings,
|mut router_data, create_order_request, grpc_headers| async move {
let response = match Box::pin(client.payment_create_order(
create_order_request,
diff --git a/crates/router/src/core/payments/gateway/incremental_authorization_gateway.rs b/crates/router/src/core/payments/gateway/incremental_authorization_gateway.rs
index 74ea81161e..373af4f2b8 100644
--- a/crates/router/src/core/payments/gateway/incremental_authorization_gateway.rs
+++ b/crates/router/src/core/payments/gateway/incremental_authorization_gateway.rs
@@ -72,11 +72,11 @@ where
RouterData<Self, types::PaymentsIncrementalAuthorizationData, types::PaymentsResponseData>,
ConnectorError,
> {
+ let rollout_settings = context.rollout_settings();
let merchant_connector_account = context.merchant_connector_account;
let processor = context.processor;
let lineage_ids = context.lineage_ids;
let header_payload = context.header_payload;
- let unified_connector_service_execution_mode = context.execution_mode;
let client = state
.grpc_client
.unified_connector_service_client
@@ -115,7 +115,9 @@ where
.map(ucs_types::UcsResourceId::PaymentAttempt);
let header_payload = state
- .get_grpc_headers_ucs(unified_connector_service_execution_mode)
+ .get_grpc_headers_ucs(rollout_settings.execution_mode)
+ .payment_method(Some(router_data.payment_method))
+ .payment_method_type(router_data.payment_method_type)
.external_vault_proxy_metadata(None)
.merchant_reference_id(merchant_reference_id)
.resource_id(resource_id)
@@ -126,7 +128,7 @@ where
state,
incremental_authorization_request,
header_payload,
- unified_connector_service_execution_mode,
+ rollout_settings,
|mut router_data, incremental_authorization_request, grpc_headers| async move {
let response = match Box::pin(client.payment_incremental_authorization(
incremental_authorization_request,
diff --git a/crates/router/src/core/payments/gateway/payment_method_token_create_gateway.rs b/crates/router/src/core/payments/gateway/payment_method_token_create_gateway.rs
index b0619cdb07..3cba317ac6 100644
--- a/crates/router/src/core/payments/gateway/payment_method_token_create_gateway.rs
+++ b/crates/router/src/core/payments/gateway/payment_method_token_create_gateway.rs
@@ -70,11 +70,11 @@ where
RouterData<Self, types::PaymentMethodTokenizationData, types::PaymentsResponseData>,
ConnectorError,
> {
+ let rollout_settings = context.rollout_settings();
let merchant_connector_account = context.merchant_connector_account;
let processor = &context.processor;
let lineage_ids = context.lineage_ids;
let header_payload = context.header_payload;
- let unified_connector_service_execution_mode = context.execution_mode;
let client = state
.grpc_client
.unified_connector_service_client
@@ -110,7 +110,9 @@ where
.map(ucs_types::UcsResourceId::PaymentAttempt);
let header_payload = state
- .get_grpc_headers_ucs(unified_connector_service_execution_mode)
+ .get_grpc_headers_ucs(rollout_settings.execution_mode)
+ .payment_method(Some(router_data.payment_method))
+ .payment_method_type(router_data.payment_method_type)
.external_vault_proxy_metadata(None)
.merchant_reference_id(merchant_reference_id)
.resource_id(resource_id)
@@ -120,7 +122,7 @@ where
state,
payment_method_tokenize_request,
header_payload,
- unified_connector_service_execution_mode,
+ rollout_settings,
|mut router_data, payment_method_tokenize_request, grpc_headers| async move {
let response = match Box::pin(client.payment_method_tokenize(
payment_method_tokenize_request,
diff --git a/crates/router/src/core/payments/gateway/post_authenticate_gateway.rs b/crates/router/src/core/payments/gateway/post_authenticate_gateway.rs
index eba7a60d66..55442d2e5f 100644
--- a/crates/router/src/core/payments/gateway/post_authenticate_gateway.rs
+++ b/crates/router/src/core/payments/gateway/post_authenticate_gateway.rs
@@ -58,11 +58,11 @@ where
RouterData<Self, types::PaymentsPostAuthenticateData, types::PaymentsResponseData>,
ConnectorError,
> {
+ let rollout_settings = context.rollout_settings();
let merchant_connector_account = context.merchant_connector_account;
let processor = &context.processor;
let lineage_ids = context.lineage_ids;
let header_payload = context.header_payload;
- let unified_connector_service_execution_mode = context.execution_mode;
complete_authorize_flow::call_unified_connector_service_post_authenticate(
router_data,
state,
@@ -70,7 +70,7 @@ where
lineage_ids,
merchant_connector_account,
processor,
- unified_connector_service_execution_mode,
+ rollout_settings,
)
.await
}
diff --git a/crates/router/src/core/payments/gateway/pre_authenticate_gateway.rs b/crates/router/src/core/payments/gateway/pre_authenticate_gateway.rs
index 36a55996f1..3db2e63c99 100644
--- a/crates/router/src/core/payments/gateway/pre_authenticate_gateway.rs
+++ b/crates/router/src/core/payments/gateway/pre_authenticate_gateway.rs
@@ -61,11 +61,11 @@ where
RouterData<Self, types::PaymentsPreAuthenticateData, types::PaymentsResponseData>,
ConnectorError,
> {
+ let rollout_settings = context.rollout_settings();
let merchant_connector_account = context.merchant_connector_account;
let processor = &context.processor;
let lineage_ids = context.lineage_ids;
let header_payload = context.header_payload;
- let unified_connector_service_execution_mode = context.execution_mode;
let connector_enum =
common_enums::connector_enums::Connector::from_str(&router_data.connector)
.change_context(ConnectorError::InvalidConnectorName)
@@ -78,7 +78,7 @@ where
merchant_connector_account,
processor,
connector_enum,
- unified_connector_service_execution_mode,
+ rollout_settings,
)
.await
.map(|(router_data, _)| router_data)
diff --git a/crates/router/src/core/payments/gateway/pre_authorize_void_gateway.rs b/crates/router/src/core/payments/gateway/pre_authorize_void_gateway.rs
index 551baf68bc..26c649cd21 100644
--- a/crates/router/src/core/payments/gateway/pre_authorize_void_gateway.rs
+++ b/crates/router/src/core/payments/gateway/pre_authorize_void_gateway.rs
@@ -67,11 +67,11 @@ where
RouterData<Self, types::PaymentsPreAuthorizeCancelData, types::PaymentsResponseData>,
ConnectorError,
> {
+ let rollout_settings = context.rollout_settings();
let merchant_connector_account = context.merchant_connector_account;
let processor = &context.processor;
let lineage_ids = context.lineage_ids;
let header_payload = context.header_payload;
- let unified_connector_service_execution_mode = context.execution_mode;
let client = state
.grpc_client
.unified_connector_service_client
@@ -109,7 +109,9 @@ where
.map(ucs_types::UcsResourceId::PaymentAttempt);
let header_payload = state
- .get_grpc_headers_ucs(unified_connector_service_execution_mode)
+ .get_grpc_headers_ucs(rollout_settings.execution_mode)
+ .payment_method(Some(router_data.payment_method))
+ .payment_method_type(router_data.payment_method_type)
.external_vault_proxy_metadata(None)
.merchant_reference_id(merchant_reference_id)
.resource_id(resource_id)
@@ -120,7 +122,7 @@ where
state,
payment_void_request,
header_payload,
- unified_connector_service_execution_mode,
+ rollout_settings,
|mut router_data, payment_void_request, grpc_headers| async move {
let response = match client
.payment_void(payment_void_request, connector_auth_metadata, grpc_headers)
diff --git a/crates/router/src/core/payments/gateway/psync_gateway.rs b/crates/router/src/core/payments/gateway/psync_gateway.rs
index c0a8730d53..2c98ed0599 100644
--- a/crates/router/src/core/payments/gateway/psync_gateway.rs
+++ b/crates/router/src/core/payments/gateway/psync_gateway.rs
@@ -139,11 +139,11 @@ where
let connector_enum =
common_enums::connector_enums::Connector::from_str(&connector_name)
.change_context(ConnectorError::InvalidConnectorName)?;
+ let rollout_settings = context.rollout_settings();
let merchant_connector_account = context.merchant_connector_account;
let processor = &context.processor;
let lineage_ids = context.lineage_ids;
let header_payload = context.header_payload;
- let unified_connector_service_execution_mode = context.execution_mode;
let is_ucs_psync_disabled = state
.conf
.grpc_client
@@ -198,7 +198,9 @@ where
.map(ucs_types::UcsResourceId::PaymentAttempt);
let header_payload = state
- .get_grpc_headers_ucs(unified_connector_service_execution_mode)
+ .get_grpc_headers_ucs(rollout_settings.execution_mode)
+ .payment_method(Some(router_data.payment_method))
+ .payment_method_type(router_data.payment_method_type)
.external_vault_proxy_metadata(None)
.merchant_reference_id(merchant_reference_id)
.resource_id(resource_id)
@@ -209,7 +211,7 @@ where
state,
payment_get_request,
header_payload,
- unified_connector_service_execution_mode,
+ rollout_settings,
|mut router_data, payment_get_request, grpc_headers| async move {
let response = match client
.payment_get(payment_get_request, connector_auth_metadata, grpc_headers)
diff --git a/crates/router/src/core/payments/gateway/session_gateway.rs b/crates/router/src/core/payments/gateway/session_gateway.rs
index 4b84e4e4aa..3574350af0 100644
--- a/crates/router/src/core/payments/gateway/session_gateway.rs
+++ b/crates/router/src/core/payments/gateway/session_gateway.rs
@@ -64,11 +64,11 @@ where
RouterData<Self, types::PaymentsSessionData, types::PaymentsResponseData>,
ConnectorError,
> {
+ let rollout_settings = context.rollout_settings();
let merchant_connector_account = context.merchant_connector_account;
let processor = &context.processor;
let lineage_ids = context.lineage_ids;
let header_payload = context.header_payload;
- let unified_connector_service_execution_mode = context.execution_mode;
let client = state
.grpc_client
.unified_connector_service_client
@@ -105,7 +105,9 @@ where
.map(ucs_types::UcsResourceId::PaymentAttempt);
let header_payload = state
- .get_grpc_headers_ucs(unified_connector_service_execution_mode)
+ .get_grpc_headers_ucs(rollout_settings.execution_mode)
+ .payment_method(Some(router_data.payment_method))
+ .payment_method_type(router_data.payment_method_type)
.external_vault_proxy_metadata(None)
.merchant_reference_id(merchant_reference_id)
.resource_id(resource_id)
@@ -116,7 +118,7 @@ where
state,
create_sdk_session_token_request,
header_payload,
- unified_connector_service_execution_mode,
+ rollout_settings,
|mut router_data, create_sdk_session_token_request, grpc_headers| async move {
let response = match Box::pin(client.create_sdk_session_token(
create_sdk_session_token_request,
diff --git a/crates/router/src/core/payments/gateway/session_token_gateway.rs b/crates/router/src/core/payments/gateway/session_token_gateway.rs
index 1b178cdb8a..6c56d653fc 100644
--- a/crates/router/src/core/payments/gateway/session_token_gateway.rs
+++ b/crates/router/src/core/payments/gateway/session_token_gateway.rs
@@ -66,11 +66,11 @@ where
RouterData<Self, types::AuthorizeSessionTokenData, types::PaymentsResponseData>,
ConnectorError,
> {
+ let rollout_settings = context.rollout_settings();
let merchant_connector_account = context.merchant_connector_account;
let processor = &context.processor;
let lineage_ids = context.lineage_ids;
let header_payload = context.header_payload;
- let unified_connector_service_execution_mode = context.execution_mode;
let client = state
.grpc_client
@@ -108,7 +108,9 @@ where
.map(ucs_types::UcsResourceId::PaymentAttempt);
let header_payload = state
- .get_grpc_headers_ucs(unified_connector_service_execution_mode)
+ .get_grpc_headers_ucs(rollout_settings.execution_mode)
+ .payment_method(Some(router_data.payment_method))
+ .payment_method_type(router_data.payment_method_type)
.external_vault_proxy_metadata(None)
.merchant_reference_id(merchant_reference_id)
.resource_id(resource_id)
@@ -118,7 +120,7 @@ where
state,
create_session_token_request,
header_payload,
- unified_connector_service_execution_mode,
+ rollout_settings,
|mut router_data, create_session_token_request, grpc_headers| async move {
let response = match client
.create_session_token(
diff --git a/crates/router/src/core/payments/gateway/setup_mandate.rs b/crates/router/src/core/payments/gateway/setup_mandate.rs
index 1775e7e17f..3607c8fd9b 100644
--- a/crates/router/src/core/payments/gateway/setup_mandate.rs
+++ b/crates/router/src/core/payments/gateway/setup_mandate.rs
@@ -62,11 +62,11 @@ where
RouterData<Self, types::SetupMandateRequestData, types::PaymentsResponseData>,
ConnectorError,
> {
+ let rollout_settings = context.rollout_settings();
let merchant_connector_account = context.merchant_connector_account;
let processor = &context.processor;
let lineage_ids = context.lineage_ids;
let header_payload = context.header_payload;
- let unified_connector_service_execution_mode = context.execution_mode;
let client = state
.grpc_client
.unified_connector_service_client
@@ -103,7 +103,9 @@ where
.map(ucs_types::UcsResourceId::PaymentAttempt);
let header_payload = state
- .get_grpc_headers_ucs(unified_connector_service_execution_mode)
+ .get_grpc_headers_ucs(rollout_settings.execution_mode)
+ .payment_method(Some(router_data.payment_method))
+ .payment_method_type(router_data.payment_method_type)
.external_vault_proxy_metadata(None)
.merchant_reference_id(merchant_reference_id)
.resource_id(resource_id)
@@ -113,7 +115,7 @@ where
state,
payment_setup_recurring_request,
header_payload,
- unified_connector_service_execution_mode,
+ rollout_settings,
|mut router_data, payment_setup_recurring_request, grpc_headers| async move {
let response = match Box::pin(client.payment_setup_recurring(
payment_setup_recurring_request,
diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rs
index 9584615834..f0f2830e60 100644
--- a/crates/router/src/core/payments/helpers.rs
+++ b/crates/router/src/core/payments/helpers.rs
@@ -2536,6 +2536,11 @@ pub struct RolloutConfig {
pub kill_switch_enabled: bool,
#[serde(default = "default_kill_switch_threshold")]
pub kill_switch_threshold: u64,
+ /// Threshold for connector declines (UCS answered, the connector refused).
+ /// Unset means declines never trip the kill switch; other failures still use
+ /// `kill_switch_threshold`.
+ #[serde(default)]
+ pub connector_decline_threshold: Option<u64>,
}
fn default_kill_switch_enabled() -> bool {
@@ -2563,6 +2568,7 @@ impl Default for RolloutConfig {
execution_mode: ExecutionMode::NotApplicable,
kill_switch_enabled: false,
kill_switch_threshold: 1,
+ connector_decline_threshold: None,
}
}
}
@@ -2577,6 +2583,28 @@ pub struct RolloutExecutionResult {
pub execution_mode: ExecutionMode,
pub kill_switch_enabled: bool,
pub kill_switch_threshold: u64,
+ /// See `RolloutConfig::connector_decline_threshold`.
+ pub connector_decline_threshold: Option<u64>,
+ /// The scope the gate evaluated this config under, set by the gate rather than by
+ /// `From<RolloutConfig>`: the config value does not know which key it was read from.
+ /// `None` until the gate runs, and on paths no gate governs.
+ pub rollout_scope: Option<String>,
+}
+
+impl RolloutExecutionResult {
+ /// The gate-resolved values the failure path needs, so a failure counts against the same
+ /// scope and thresholds the gate used rather than recomputing either.
+ pub fn rollout_settings(
+ &self,
+ ) -> crate::core::unified_connector_service::kill_switch::RolloutSettings {
+ crate::core::unified_connector_service::kill_switch::RolloutSettings {
+ execution_mode: self.execution_mode,
+ kill_switch_enabled: self.kill_switch_enabled,
+ kill_switch_threshold: self.kill_switch_threshold,
+ connector_decline_threshold: self.connector_decline_threshold,
+ rollout_scope: self.rollout_scope.clone(),
+ }
+ }
}
impl Default for RolloutExecutionResult {
@@ -2587,6 +2615,8 @@ impl Default for RolloutExecutionResult {
execution_mode: ExecutionMode::NotApplicable,
kill_switch_enabled: false,
kill_switch_threshold: 1,
+ connector_decline_threshold: None,
+ rollout_scope: None,
}
}
}
@@ -2678,6 +2708,7 @@ impl From<RolloutConfig> for RolloutExecutionResult {
execution_mode: config.execution_mode,
kill_switch_enabled: config.kill_switch_enabled,
kill_switch_threshold: config.kill_switch_threshold,
+ connector_decline_threshold: config.connector_decline_threshold,
// Proxy override is sourced from the env-configured comparison
// service, not from the DB rollout config — populated by the caller
// after conversion.
diff --git a/crates/router/src/core/payouts.rs b/crates/router/src/core/payouts.rs
index 0b8704e98d..ebde064573 100644
--- a/crates/router/src/core/payouts.rs
+++ b/crates/router/src/core/payouts.rs
@@ -4441,7 +4441,7 @@ pub async fn decide_unified_connector_service_payout<F: Clone>(
// Extract previous gateway from payment data
let previous_gateway = extract_gateway_system_from_payouts(payout_data);
- let (execution_path, updated_state) = should_call_unified_connector_service(
+ let (execution_path, updated_state, rollout_result) = should_call_unified_connector_service(
state,
platform.get_processor(),
router_data,
@@ -4496,6 +4496,10 @@ pub async fn decide_unified_connector_service_payout<F: Clone>(
lineage_ids,
merchant_connector_account,
execution_path,
+ kill_switch_enabled: rollout_result.kill_switch_enabled,
+ kill_switch_threshold: rollout_result.kill_switch_threshold,
+ connector_decline_threshold: rollout_result.connector_decline_threshold,
+ rollout_scope: rollout_result.rollout_scope.clone(),
execution_mode,
};
// Update feature metadata to track Direct routing usage for stickiness
diff --git a/crates/router/src/core/payouts/gateway/cancel_gateway.rs b/crates/router/src/core/payouts/gateway/cancel_gateway.rs
index a82b0fecd2..856f3a22e1 100644
--- a/crates/router/src/core/payouts/gateway/cancel_gateway.rs
+++ b/crates/router/src/core/payouts/gateway/cancel_gateway.rs
@@ -58,11 +58,11 @@ where
RouterData<Self, types::PayoutsData, types::PayoutsResponseData>,
ConnectorError,
> {
+ let rollout_settings = context.rollout_settings();
let merchant_connector_account = context.merchant_connector_account;
let processor = &context.processor;
let lineage_ids = context.lineage_ids;
let header_payload = context.header_payload;
- let unified_connector_service_execution_mode = context.execution_mode;
let client = state
.grpc_client
.unified_connector_service_client
@@ -92,7 +92,9 @@ where
.map(ucs_types::UcsResourceId::PayoutAttempt);
let grpc_headers = state
- .get_grpc_headers_ucs(unified_connector_service_execution_mode)
+ .get_grpc_headers_ucs(rollout_settings.execution_mode)
+ .payment_method(Some(router_data.payment_method))
+ .payment_method_type(router_data.payment_method_type)
.external_vault_proxy_metadata(None)
.merchant_reference_id(merchant_reference_id)
.resource_id(resource_id)
@@ -110,7 +112,7 @@ where
state,
granular_payout_void_request,
grpc_headers,
- unified_connector_service_execution_mode,
+ rollout_settings,
|mut router_data, granular_payout_void_request, grpc_headers| async move {
let response = match Box::pin(client.payout_void(
granular_payout_void_request,
diff --git a/crates/router/src/core/payouts/gateway/create_gateway.rs b/crates/router/src/core/payouts/gateway/create_gateway.rs
index 4381c52d97..919a21fa83 100644
--- a/crates/router/src/core/payouts/gateway/create_gateway.rs
+++ b/crates/router/src/core/payouts/gateway/create_gateway.rs
@@ -58,11 +58,11 @@ where
RouterData<Self, types::PayoutsData, types::PayoutsResponseData>,
ConnectorError,
> {
+ let rollout_settings = context.rollout_settings();
let merchant_connector_account = context.merchant_connector_account;
let processor = &context.processor;
let lineage_ids = context.lineage_ids;
let header_payload = context.header_payload;
- let unified_connector_service_execution_mode = context.execution_mode;
let client = state
.grpc_client
.unified_connector_service_client
@@ -97,7 +97,9 @@ where
.map(ucs_types::UcsResourceId::PayoutAttempt);
let grpc_headers = state
- .get_grpc_headers_ucs(unified_connector_service_execution_mode)
+ .get_grpc_headers_ucs(rollout_settings.execution_mode)
+ .payment_method(Some(router_data.payment_method))
+ .payment_method_type(router_data.payment_method_type)
.external_vault_proxy_metadata(None)
.merchant_reference_id(merchant_reference_id)
.resource_id(resource_id)
@@ -115,7 +117,7 @@ where
state,
granular_payout_create_request,
grpc_headers,
- unified_connector_service_execution_mode,
+ rollout_settings,
|mut router_data, granular_payout_create_request, grpc_headers| async move {
let response = match Box::pin(client.payout_create(
granular_payout_create_request,
diff --git a/crates/router/src/core/payouts/gateway/eligibility_gateway.rs b/crates/router/src/core/payouts/gateway/eligibility_gateway.rs
index 1c773a22a7..cf32544150 100644
--- a/crates/router/src/core/payouts/gateway/eligibility_gateway.rs
+++ b/crates/router/src/core/payouts/gateway/eligibility_gateway.rs
@@ -58,11 +58,11 @@ where
RouterData<Self, types::PayoutsData, types::PayoutsResponseData>,
ConnectorError,
> {
+ let rollout_settings = context.rollout_settings();
let merchant_connector_account = context.merchant_connector_account;
let processor = &context.processor;
let lineage_ids = context.lineage_ids;
let header_payload = context.header_payload;
- let unified_connector_service_execution_mode = context.execution_mode;
let client = state
.grpc_client
.unified_connector_service_client
@@ -92,7 +92,9 @@ where
.map(ucs_types::UcsResourceId::PayoutAttempt);
let grpc_headers = state
- .get_grpc_headers_ucs(unified_connector_service_execution_mode)
+ .get_grpc_headers_ucs(rollout_settings.execution_mode)
+ .payment_method(Some(router_data.payment_method))
+ .payment_method_type(router_data.payment_method_type)
.external_vault_proxy_metadata(None)
.merchant_reference_id(merchant_reference_id)
.resource_id(resource_id)
@@ -110,7 +112,7 @@ where
state,
granular_payout_eligibility_request,
grpc_headers,
- unified_connector_service_execution_mode,
+ rollout_settings,
|mut router_data, granular_payout_eligibility_request, grpc_headers| async move {
let response = Box::pin(client.payout_eligibility(
granular_payout_eligibility_request,
diff --git a/crates/router/src/core/payouts/gateway/fulfill_gateway.rs b/crates/router/src/core/payouts/gateway/fulfill_gateway.rs
index 0d68678843..c911d5275d 100644
--- a/crates/router/src/core/payouts/gateway/fulfill_gateway.rs
+++ b/crates/router/src/core/payouts/gateway/fulfill_gateway.rs
@@ -58,11 +58,11 @@ where
RouterData<Self, types::PayoutsData, types::PayoutsResponseData>,
ConnectorError,
> {
+ let rollout_settings = context.rollout_settings();
let merchant_connector_account = context.merchant_connector_account;
let processor = &context.processor;
let lineage_ids = context.lineage_ids;
let header_payload = context.header_payload;
- let unified_connector_service_execution_mode = context.execution_mode;
let client = state
.grpc_client
.unified_connector_service_client
@@ -92,7 +92,9 @@ where
.map(ucs_types::UcsResourceId::PayoutAttempt);
let grpc_headers = state
- .get_grpc_headers_ucs(unified_connector_service_execution_mode)
+ .get_grpc_headers_ucs(rollout_settings.execution_mode)
+ .payment_method(Some(router_data.payment_method))
+ .payment_method_type(router_data.payment_method_type)
.external_vault_proxy_metadata(None)
.merchant_reference_id(merchant_reference_id)
.resource_id(resource_id)
@@ -110,7 +112,7 @@ where
state,
granular_payout_transfer_request,
grpc_headers,
- unified_connector_service_execution_mode,
+ rollout_settings,
|mut router_data, granular_payout_transfer_request, grpc_headers| async move {
let response = match Box::pin(client.payout_transfer(
granular_payout_transfer_request,
diff --git a/crates/router/src/core/payouts/gateway/quote_gateway.rs b/crates/router/src/core/payouts/gateway/quote_gateway.rs
index 3c8aa6fd64..a39e065a69 100644
--- a/crates/router/src/core/payouts/gateway/quote_gateway.rs
+++ b/crates/router/src/core/payouts/gateway/quote_gateway.rs
@@ -58,11 +58,11 @@ where
RouterData<Self, types::PayoutsData, types::PayoutsResponseData>,
ConnectorError,
> {
+ let rollout_settings = context.rollout_settings();
let merchant_connector_account = context.merchant_connector_account;
let processor = &context.processor;
let lineage_ids = context.lineage_ids;
let header_payload = context.header_payload;
- let unified_connector_service_execution_mode = context.execution_mode;
let client = state
.grpc_client
.unified_connector_service_client
@@ -92,7 +92,9 @@ where
.map(ucs_types::UcsResourceId::PayoutAttempt);
let grpc_headers = state
- .get_grpc_headers_ucs(unified_connector_service_execution_mode)
+ .get_grpc_headers_ucs(rollout_settings.execution_mode)
+ .payment_method(Some(router_data.payment_method))
+ .payment_method_type(router_data.payment_method_type)
.external_vault_proxy_metadata(None)
.merchant_reference_id(merchant_reference_id)
.resource_id(resource_id)
@@ -110,7 +112,7 @@ where
state,
granular_payout_stage_request,
grpc_headers,
- unified_connector_service_execution_mode,
+ rollout_settings,
|mut router_data, granular_payout_stage_request, grpc_headers| async move {
let response = match Box::pin(client.payout_stage(
granular_payout_stage_request,
diff --git a/crates/router/src/core/payouts/gateway/recipient_account_gateway.rs b/crates/router/src/core/payouts/gateway/recipient_account_gateway.rs
index 5bccc4d433..e533cb565f 100644
--- a/crates/router/src/core/payouts/gateway/recipient_account_gateway.rs
+++ b/crates/router/src/core/payouts/gateway/recipient_account_gateway.rs
@@ -58,11 +58,11 @@ where
RouterData<Self, types::PayoutsData, types::PayoutsResponseData>,
ConnectorError,
> {
+ let rollout_settings = context.rollout_settings();
let merchant_connector_account = context.merchant_connector_account;
let processor = &context.processor;
let lineage_ids = context.lineage_ids;
let header_payload = context.header_payload;
- let unified_connector_service_execution_mode = context.execution_mode;
let client = state
.grpc_client
.unified_connector_service_client
@@ -92,7 +92,9 @@ where
.map(ucs_types::UcsResourceId::PayoutAttempt);
let grpc_headers = state
- .get_grpc_headers_ucs(unified_connector_service_execution_mode)
+ .get_grpc_headers_ucs(rollout_settings.execution_mode)
+ .payment_method(Some(router_data.payment_method))
+ .payment_method_type(router_data.payment_method_type)
.external_vault_proxy_metadata(None)
.merchant_reference_id(merchant_reference_id)
.resource_id(resource_id)
@@ -109,7 +111,7 @@ where
state,
granular_payout_enroll_disburse_account_request,
grpc_headers,
- unified_connector_service_execution_mode,
+ rollout_settings,
|mut router_data, granular_payout_enroll_disburse_account_request, grpc_headers| async move {
let response = match Box::pin(client.payout_enroll_disburse_account(
granular_payout_enroll_disburse_account_request,
diff --git a/crates/router/src/core/payouts/gateway/recipient_gateway.rs b/crates/router/src/core/payouts/gateway/recipient_gateway.rs
index 6c0ca37bf7..dbe32ec04a 100644
--- a/crates/router/src/core/payouts/gateway/recipient_gateway.rs
+++ b/crates/router/src/core/payouts/gateway/recipient_gateway.rs
@@ -58,11 +58,11 @@ where
RouterData<Self, types::PayoutsData, types::PayoutsResponseData>,
ConnectorError,
> {
+ let rollout_settings = context.rollout_settings();
let merchant_connector_account = context.merchant_connector_account;
let processor = &context.processor;
let lineage_ids = context.lineage_ids;
let header_payload = context.header_payload;
- let unified_connector_service_execution_mode = context.execution_mode;
let client = state
.grpc_client
.unified_connector_service_client
@@ -92,7 +92,9 @@ where
.map(ucs_types::UcsResourceId::PayoutAttempt);
let grpc_headers = state
- .get_grpc_headers_ucs(unified_connector_service_execution_mode)
+ .get_grpc_headers_ucs(rollout_settings.execution_mode)
+ .payment_method(Some(router_data.payment_method))
+ .payment_method_type(router_data.payment_method_type)
.external_vault_proxy_metadata(None)
.merchant_reference_id(merchant_reference_id)
.resource_id(resource_id)
@@ -109,7 +111,7 @@ where
state,
granular_payout_create_recipient_request,
grpc_headers,
- unified_connector_service_execution_mode,
+ rollout_settings,
|mut router_data, granular_payout_create_recipient_request, grpc_headers| async move {
let response = match Box::pin(client.payout_create_recipient(
granular_payout_create_recipient_request,
diff --git a/crates/router/src/core/payouts/gateway/sync_gateway.rs b/crates/router/src/core/payouts/gateway/sync_gateway.rs
index a983dba1ff..ca4f41a35b 100644
--- a/crates/router/src/core/payouts/gateway/sync_gateway.rs
+++ b/crates/router/src/core/payouts/gateway/sync_gateway.rs
@@ -58,11 +58,11 @@ where
RouterData<Self, types::PayoutsData, types::PayoutsResponseData>,
ConnectorError,
> {
+ let rollout_settings = context.rollout_settings();
let merchant_connector_account = context.merchant_connector_account;
let processor = &context.processor;
let lineage_ids = context.lineage_ids;
let header_payload = context.header_payload;
- let unified_connector_service_execution_mode = context.execution_mode;
let client = state
.grpc_client
.unified_connector_service_client
@@ -92,7 +92,9 @@ where
.map(ucs_types::UcsResourceId::PayoutAttempt);
let grpc_headers = state
- .get_grpc_headers_ucs(unified_connector_service_execution_mode)
+ .get_grpc_headers_ucs(rollout_settings.execution_mode)
+ .payment_method(Some(router_data.payment_method))
+ .payment_method_type(router_data.payment_method_type)
.external_vault_proxy_metadata(None)
.merchant_reference_id(merchant_reference_id)
.resource_id(resource_id)
@@ -110,7 +112,7 @@ where
state,
granular_payout_get_request,
grpc_headers,
- unified_connector_service_execution_mode,
+ rollout_settings,
|mut router_data, granular_payout_get_request, grpc_headers| async move {
let response = match Box::pin(client.payout_get(
granular_payout_get_request,
diff --git a/crates/router/src/core/refunds.rs b/crates/router/src/core/refunds.rs
index f67498a78f..8c94001277 100644
--- a/crates/router/src/core/refunds.rs
+++ b/crates/router/src/core/refunds.rs
@@ -210,7 +210,7 @@ pub async fn refund_reverse_core(
.await?;
router_data.request.reason = req.cancellation_reason.clone();
- let (execution_path, updated_state) =
+ let (execution_path, updated_state, rollout_result) =
unified_connector_service::should_call_unified_connector_service(
&state,
processor,
@@ -231,6 +231,10 @@ pub async fn refund_reverse_core(
lineage_ids,
merchant_connector_account: merchant_connector_account.clone(),
execution_path,
+ kill_switch_enabled: rollout_result.kill_switch_enabled,
+ kill_switch_threshold: rollout_result.kill_switch_threshold,
+ connector_decline_threshold: rollout_result.connector_decline_threshold,
+ rollout_scope: rollout_result.rollout_scope.clone(),
execution_mode,
};
let add_access_token_result = Box::pin(access_token::add_access_token(
@@ -262,7 +266,13 @@ pub async fn refund_reverse_core(
&updated_state,
processor,
router_data,
- ExecutionMode::Primary,
+ unified_connector_service::kill_switch::RolloutSettings {
+ execution_mode: ExecutionMode::Primary,
+ kill_switch_enabled: rollout_result.kill_switch_enabled,
+ kill_switch_threshold: rollout_result.kill_switch_threshold,
+ connector_decline_threshold: rollout_result.connector_decline_threshold,
+ rollout_scope: rollout_result.rollout_scope.clone(),
+ },
merchant_connector_account,
)
.await
@@ -534,7 +544,7 @@ pub async fn trigger_refund_to_gateway(
)
.await?;
- let (execution_path, updated_state) =
+ let (execution_path, updated_state, rollout_result) =
unified_connector_service::should_call_unified_connector_service(
state,
platform.get_processor(),
@@ -568,6 +578,10 @@ pub async fn trigger_refund_to_gateway(
lineage_ids,
merchant_connector_account: merchant_connector_account.clone(),
execution_path,
+ kill_switch_enabled: rollout_result.kill_switch_enabled,
+ kill_switch_threshold: rollout_result.kill_switch_threshold,
+ connector_decline_threshold: rollout_result.connector_decline_threshold,
+ rollout_scope: rollout_result.rollout_scope.clone(),
execution_mode,
};
@@ -605,7 +619,13 @@ pub async fn trigger_refund_to_gateway(
state,
platform.get_processor(),
router_data.clone(),
- ExecutionMode::Primary,
+ unified_connector_service::kill_switch::RolloutSettings {
+ execution_mode: ExecutionMode::Primary,
+ kill_switch_enabled: rollout_result.kill_switch_enabled,
+ kill_switch_threshold: rollout_result.kill_switch_threshold,
+ connector_decline_threshold: rollout_result.connector_decline_threshold,
+ rollout_scope: rollout_result.rollout_scope.clone(),
+ },
merchant_connector_account,
)
.await
@@ -964,7 +984,9 @@ async fn execute_refund_execute_via_direct_with_ucs_shadow(
&ucs_state,
ucs_platform.get_processor(),
ucs_router_data,
- ExecutionMode::Shadow,
+ unified_connector_service::kill_switch::RolloutSettings::without_kill_switch(
+ ExecutionMode::Shadow,
+ ),
merchant_connector_account,
)
.await;
@@ -1209,7 +1231,7 @@ pub async fn sync_refund_with_gateway(
// Access token available or not needed - proceed with execution
// Check which gateway system to use for refund sync
- let (execution_path, updated_state) =
+ let (execution_path, updated_state, rollout_result) =
unified_connector_service::should_call_unified_connector_service(
state,
platform.get_processor(),
@@ -1243,6 +1265,10 @@ pub async fn sync_refund_with_gateway(
lineage_ids,
merchant_connector_account: merchant_connector_account.clone(),
execution_path,
+ kill_switch_enabled: rollout_result.kill_switch_enabled,
+ kill_switch_threshold: rollout_result.kill_switch_threshold,
+ connector_decline_threshold: rollout_result.connector_decline_threshold,
+ rollout_scope: rollout_result.rollout_scope.clone(),
execution_mode,
};
@@ -1276,7 +1302,13 @@ pub async fn sync_refund_with_gateway(
state,
platform.get_processor(),
router_data.clone(),
- ExecutionMode::Primary,
+ unified_connector_service::kill_switch::RolloutSettings {
+ execution_mode: ExecutionMode::Primary,
+ kill_switch_enabled: rollout_result.kill_switch_enabled,
+ kill_switch_threshold: rollout_result.kill_switch_threshold,
+ connector_decline_threshold: rollout_result.connector_decline_threshold,
+ rollout_scope: rollout_result.rollout_scope.clone(),
+ },
merchant_connector_account,
)
.await
@@ -1522,7 +1554,9 @@ async fn execute_refund_sync_via_direct_with_ucs_shadow(
&state,
&processor,
router_data,
- ExecutionMode::Shadow,
+ unified_connector_service::kill_switch::RolloutSettings::without_kill_switch(
+ ExecutionMode::Shadow,
+ ),
merchant_connector_account,
)
.await;
diff --git a/crates/router/src/core/unified_connector_service.rs b/crates/router/src/core/unified_connector_service.rs
index 19b5f54832..d5e24357c4 100644
--- a/crates/router/src/core/unified_connector_service.rs
+++ b/crates/router/src/core/unified_connector_service.rs
@@ -53,8 +53,8 @@ use crate::{
helpers::{
is_config_flag_enabled, is_googlepay_predecrypted_flow_supported,
should_execute_based_on_rollout, should_execute_based_on_rollout_with_precedence,
- MerchantConnectorAccountType, ProxyOverride, WebhookRolloutConfig,
- WebhookRolloutExecutionResult,
+ MerchantConnectorAccountType, ProxyOverride, RolloutExecutionResult,
+ WebhookRolloutConfig, WebhookRolloutExecutionResult,
},
OperationSessionGetters, OperationSessionSetters,
},
@@ -925,7 +925,7 @@ pub async fn should_call_unified_connector_service<F: Clone, T, R>(
call_connector_action: CallConnectorAction,
shadow_ucs_call_connector_action: Option<CallConnectorAction>,
transaction_type: common_enums::TransactionType,
-) -> RouterResult<(ExecutionPath, SessionState)>
+) -> RouterResult<(ExecutionPath, SessionState, RolloutExecutionResult)>
where
R: Send + Sync + Clone,
{
@@ -968,7 +968,7 @@ where
determine_connector_integration_type(state, connector_enum).await?;
// Try keys highest → lowest precedence, use first match found
- let rollout_result =
+ let mut rollout_result =
should_execute_based_on_rollout_with_precedence(state, &rollout_keys).await?;
// Single decision point using pattern matching
@@ -1046,19 +1046,32 @@ where
router_data.payment_method_type,
);
+ // This is the scope the decision is made under. Every connector call the decision
+ // authorises counts against it, including the flows that inherit it without gating
+ // for themselves.
+ rollout_result.rollout_scope = Some(rollout_scope.clone());
+
if Box::pin(kill_switch::is_kill_switched(
state,
&rollout_scope,
- rollout_result.kill_switch_enabled,
- rollout_result.kill_switch_threshold,
+ rollout_result.rollout_settings(),
))
.await
{
+ // Same dimensions as UCS_KILL_SWITCH_COUNTER_INCREMENTED so one alert can
+ // correlate "counter rose" with "traffic actually diverted".
router_env::logger::warn!(
+ rollout_scope = %rollout_scope,
merchant_id = %merchant_id,
connector = %connector_name,
flow = %flow_name,
- "UCS kill switch counter exceeds threshold for this scope, routing to shadow"
+ payment_method = ?router_data.payment_method,
+ payment_method_type = ?router_data.payment_method_type,
+ kill_switch_enabled = rollout_result.kill_switch_enabled,
+ threshold = rollout_result.kill_switch_threshold,
+ connector_decline_threshold = ?rollout_result.connector_decline_threshold,
+ request_id = ?state.request_id,
+ "UCS_KILL_SWITCH_DIVERTED_TO_SHADOW"
);
gateway_system = GatewaySystem::Direct;
execution_path = ExecutionPath::ShadowUnifiedConnectorService;
@@ -1102,7 +1115,7 @@ where
flow_name
);
- Ok((execution_path, session_state))
+ Ok((execution_path, session_state, rollout_result))
}
/// Creates a new SessionState with proxy configuration updated from the override
@@ -3808,7 +3821,7 @@ pub async fn ucs_logging_wrapper<T, F, Fut, Req, Resp, GrpcReq, GrpcResp, FlowOu
state: &SessionState,
grpc_request: GrpcReq,
grpc_header_builder: external_services::grpc_client::GrpcHeadersUcsBuilderFinal,
- execution_mode: ExecutionMode,
+ rollout_settings: kill_switch::RolloutSettings,
handler: F,
) -> RouterResult<(RouterData<T, Req, Resp>, FlowOutput)>
where
@@ -3876,9 +3889,31 @@ where
// Create and emit connector event after UCS call
let (status_code, response_body, router_result) = match result {
Ok((updated_router_data, flow_output, grpc_response)) => {
- let status = updated_router_data
- .connector_http_status_code
- .unwrap_or(200);
+ // Every handler sets this from the UCS response, so `None` here means a handler
+ // forgot. Record 0 — UCS's own value for "no HTTP status" and already present in
+ // connector_events — rather than a fabricated 200 that reads as success.
+ let status = updated_router_data.connector_http_status_code.unwrap_or(0);
+
+ // UCS answered gRPC OK with a connector 2xx and the connector still refused
+ // the payment. Counted against `connector_decline_threshold`, so it is a
+ // no-op unless the scope sets one.
+ if updated_router_data.response.is_err() {
+ if let Ok(flow_name) = get_flow_name::<T>() {
+ kill_switch::record_decline(
+ state,
+ kill_switch::UcsFailureContext {
+ merchant_id: merchant_id.get_string_repr(),
+ connector_name: &connector_name,
+ flow_name: &flow_name,
+ payment_id: &payment_id,
+ payment_method,
+ payment_method_type,
+ },
+ rollout_settings.clone(),
+ )
+ .await;
+ }
+ }
// Log the actual gRPC response with masking
let grpc_response_body = hyperswitch_masking::masked_serialize(&grpc_response)
@@ -3909,7 +3944,7 @@ where
payment_method,
payment_method_type,
},
- execution_mode,
+ rollout_settings.clone(),
error.current_context(),
)
.await;
@@ -3950,7 +3985,7 @@ where
payment_method,
payment_method_type,
},
- execution_mode,
+ rollout_settings.clone(),
error.current_context(),
)
.await;
@@ -4006,7 +4041,7 @@ where
status_code,
response_body,
external_latency,
- execution_mode,
+ rollout_settings.execution_mode,
);
// Set external latency on router data
@@ -4026,7 +4061,7 @@ pub async fn ucs_logging_wrapper_granular<T, F, Fut, Req, Resp, GrpcReq, FlowOut
state: &SessionState,
grpc_request: GrpcReq,
grpc_header_builder: external_services::grpc_client::GrpcHeadersUcsBuilderFinal,
- execution_mode: ExecutionMode,
+ rollout_settings: kill_switch::RolloutSettings,
handler: F,
) -> CustomResult<(RouterData<T, Req, Resp>, FlowOutput), UnifiedConnectorServiceError>
where
@@ -4095,9 +4130,31 @@ where
// Create and emit connector event after UCS call
let (status_code, response_body, router_result) = match result {
Ok((updated_router_data, flow_output, grpc_response)) => {
- let status = updated_router_data
- .connector_http_status_code
- .unwrap_or(200);
+ // Every handler sets this from the UCS response, so `None` here means a handler
+ // forgot. Record 0 — UCS's own value for "no HTTP status" and already present in
+ // connector_events — rather than a fabricated 200 that reads as success.
+ let status = updated_router_data.connector_http_status_code.unwrap_or(0);
+
+ // UCS answered gRPC OK with a connector 2xx and the connector still refused
+ // the payment. Counted against `connector_decline_threshold`, so it is a
+ // no-op unless the scope sets one.
+ if updated_router_data.response.is_err() {
+ if let Ok(flow_name) = get_flow_name::<T>() {
+ kill_switch::record_decline(
+ state,
+ kill_switch::UcsFailureContext {
+ merchant_id: merchant_id.get_string_repr(),
+ connector_name: &connector_name,
+ flow_name: &flow_name,
+ payment_id: &payment_id,
+ payment_method,
+ payment_method_type,
+ },
+ rollout_settings.clone(),
+ )
+ .await;
+ }
+ }
// Log the actual gRPC response
let grpc_response_body = hyperswitch_masking::masked_serialize(&grpc_response)
@@ -4128,7 +4185,7 @@ where
payment_method,
payment_method_type,
},
- execution_mode,
+ rollout_settings.clone(),
error.current_context(),
)
.await;
@@ -4170,7 +4227,7 @@ where
payment_method,
payment_method_type,
},
- execution_mode,
+ rollout_settings.clone(),
error.current_context(),
)
.await;
@@ -4227,7 +4284,7 @@ where
status_code,
response_body,
external_latency,
- execution_mode,
+ rollout_settings.execution_mode,
);
// Set external latency on router data
@@ -4320,7 +4377,7 @@ pub async fn call_unified_connector_service_for_refund_execute(
state: &SessionState,
processor: &Processor,
router_data: RouterData<refunds::Execute, RefundsData, RefundsResponseData>,
- execution_mode: ExecutionMode,
+ rollout_settings: kill_switch::RolloutSettings,
#[cfg(feature = "v1")] merchant_connector_account: MerchantConnectorAccountType,
#[cfg(feature = "v2")] merchant_connector_account: MerchantConnectorAccountTypeDetails,
) -> RouterResult<RouterData<refunds::Execute, RefundsData, RefundsResponseData>> {
@@ -4366,7 +4423,9 @@ pub async fn call_unified_connector_service_for_refund_execute(
})
.map(ucs_types::UcsResourceId::Refund);
let grpc_header_builder = state
- .get_grpc_headers_ucs(execution_mode)
+ .get_grpc_headers_ucs(rollout_settings.execution_mode)
+ .payment_method(Some(router_data.payment_method))
+ .payment_method_type(router_data.payment_method_type)
.lineage_ids(lineage_ids)
.external_vault_proxy_metadata(None)
.merchant_reference_id(merchant_reference_id)
@@ -4380,7 +4439,7 @@ pub async fn call_unified_connector_service_for_refund_execute(
state,
ucs_refund_request,
grpc_header_builder,
- execution_mode,
+ rollout_settings.clone(),
|mut router_data, grpc_request, grpc_headers| async move {
// Call UCS payment_refund method
// UCS connector errors are handled by the wrapper — see `ucs_logging_wrapper`.
@@ -4415,7 +4474,7 @@ pub async fn call_unified_connector_service_for_refund_sync(
state: &SessionState,
processor: &Processor,
router_data: RouterData<refunds::RSync, RefundsData, RefundsResponseData>,
- execution_mode: ExecutionMode,
+ rollout_settings: kill_switch::RolloutSettings,
#[cfg(feature = "v1")] merchant_connector_account: MerchantConnectorAccountType,
#[cfg(feature = "v2")] merchant_connector_account: MerchantConnectorAccountTypeDetails,
) -> RouterResult<RouterData<refunds::RSync, RefundsData, RefundsResponseData>> {
@@ -4462,7 +4521,9 @@ pub async fn call_unified_connector_service_for_refund_sync(
.map(ucs_types::UcsResourceId::Refund);
let grpc_header_builder = state
- .get_grpc_headers_ucs(execution_mode)
+ .get_grpc_headers_ucs(rollout_settings.execution_mode)
+ .payment_method(Some(router_data.payment_method))
+ .payment_method_type(router_data.payment_method_type)
.lineage_ids(lineage_ids)
.external_vault_proxy_metadata(None)
.merchant_reference_id(merchant_reference_id)
@@ -4476,7 +4537,7 @@ pub async fn call_unified_connector_service_for_refund_sync(
state,
ucs_refund_sync_request,
grpc_header_builder,
- execution_mode,
+ rollout_settings.clone(),
|mut router_data, grpc_request, grpc_headers| async move {
// Call UCS refund_sync method
// UCS connector errors are handled by the wrapper — see `ucs_logging_wrapper`.
@@ -4511,7 +4572,7 @@ pub async fn call_unified_connector_service_for_refund_void_post_refund(
state: &SessionState,
processor: &Processor,
router_data: RouterData<refunds::VoidPostRefund, RefundsData, RefundsResponseData>,
- execution_mode: ExecutionMode,
+ rollout_settings: kill_switch::RolloutSettings,
#[cfg(feature = "v1")] merchant_connector_account: MerchantConnectorAccountType,
#[cfg(feature = "v2")] merchant_connector_account: MerchantConnectorAccountTypeDetails,
) -> RouterResult<RefundReverseUcsResponse> {
@@ -4550,7 +4611,9 @@ pub async fn call_unified_connector_service_for_refund_void_post_refund(
.transpose()?
.map(ucs_types::UcsResourceId::Refund);
let grpc_header_builder = state
- .get_grpc_headers_ucs(execution_mode)
+ .get_grpc_headers_ucs(rollout_settings.execution_mode)
+ .payment_method(Some(router_data.payment_method))
+ .payment_method_type(router_data.payment_method_type)
.lineage_ids(lineage_ids)
.external_vault_proxy_metadata(None)
.merchant_reference_id(merchant_reference_id)
@@ -4561,7 +4624,7 @@ pub async fn call_unified_connector_service_for_refund_void_post_refund(
state,
grpc_request,
grpc_header_builder,
- execution_mode,
+ rollout_settings.clone(),
|mut router_data, grpc_request, grpc_headers| async move {
let grpc_response = ucs_client
.refund_void_post_refund(grpc_request, connector_auth_metadata, grpc_headers)
@@ -4653,6 +4716,8 @@ pub async fn call_unified_connector_service_for_surcharge_calculate(
let grpc_header_builder = state
.get_grpc_headers_ucs(ExecutionMode::Primary)
+ .payment_method(None)
+ .payment_method_type(None)
.lineage_ids(lineage_ids)
.external_vault_proxy_metadata(None)
.merchant_reference_id(merchant_reference_id)
@@ -4774,6 +4839,8 @@ pub async fn call_unified_connector_service_for_notify_connector(
let grpc_header_builder = state
.get_grpc_headers_ucs(ExecutionMode::Primary)
+ .payment_method(None)
+ .payment_method_type(None)
.lineage_ids(lineage_ids)
.external_vault_proxy_metadata(None)
.merchant_reference_id(merchant_reference_id)
diff --git a/crates/router/src/core/unified_connector_service/frm.rs b/crates/router/src/core/unified_connector_service/frm.rs
index 5f5a41d6d0..384438523c 100644
--- a/crates/router/src/core/unified_connector_service/frm.rs
+++ b/crates/router/src/core/unified_connector_service/frm.rs
@@ -252,6 +252,8 @@ pub async fn call_unified_connector_service_for_frm_notification(
let grpc_headers = state
.get_grpc_headers_ucs(common_enums::ExecutionMode::Primary)
+ .payment_method(None)
+ .payment_method_type(None)
.lineage_ids(LineageIds::new(
processor.get_account().get_id().clone(),
context.profile_id.clone(),
diff --git a/crates/router/src/core/unified_connector_service/kill_switch.rs b/crates/router/src/core/unified_connector_service/kill_switch.rs
index abcd220c2b..488e041f7a 100644
--- a/crates/router/src/core/unified_connector_service/kill_switch.rs
+++ b/crates/router/src/core/unified_connector_service/kill_switch.rs
@@ -16,23 +16,37 @@ use router_env::logger;
use crate::{
consts,
- core::{
- errors, metrics,
- unified_connector_service::{
- build_merchant_rollout_scope, determine_connector_integration_type,
- },
- },
+ core::{errors, metrics, unified_connector_service::determine_connector_integration_type},
routes::SessionState,
};
-/// Hash field name for the failure counter.
+/// Hash field holding the integration-failure counter. Named `counter` rather than something
+/// symmetrical with the decline field because scopes in flight already hold their count under
+/// this name; renaming it would silently reset every live counter on deploy.
const COUNTER_FIELD: &str = "counter";
+/// Hash field holding the connector-decline counter, in the same hash as [`COUNTER_FIELD`].
+/// Separate because the two classes are measured against separate thresholds: sharing one
+/// field would mean `connector_decline_threshold: N` trips on N failures of any kind rather
+/// than N declines.
+const DECLINE_COUNTER_FIELD: &str = "counter_connector_decline";
+
/// Whether the counter has reached or exceeded the threshold.
fn exceeds_threshold(count: u64, threshold: u64) -> bool {
count >= threshold
}
+impl UcsFailureClass {
+ /// The hash field this class counts into. Each class has its own field so it is measured
+ /// only against its own threshold.
+ fn counter_field(self) -> &'static str {
+ match self {
+ Self::ConnectorDecline => DECLINE_COUNTER_FIELD,
+ Self::IntegrationFailure => COUNTER_FIELD,
+ }
+ }
+}
+
/// Redis key holding the failure counter for a scope.
fn counter_key(rollout_scope: &str) -> String {
format!("{}_{rollout_scope}", consts::UCS_KILL_SWITCH_REDIS_PREFIX)
@@ -51,6 +65,41 @@ fn rollout_scope_in(key_or_scope: &str) -> &str {
}
}
+/// Both of a scope's counters and whether each has reached its own threshold.
+struct ScopeCounters {
+ count: u64,
+ exceeded: bool,
+ decline_count: u64,
+ decline_exceeded: bool,
+}
+
+/// Reads both counters for a scope. Each class is compared only against its own threshold;
+/// a scope with no `connector_decline_threshold` never trips on declines.
+async fn read_counters(
+ state: &SessionState,
+ rollout_scope: &str,
+ settings: &RolloutSettings,
+) -> error_stack::Result<ScopeCounters, storage_impl::errors::RedisError> {
+ let count = read_counter(state, rollout_scope, UcsFailureClass::IntegrationFailure).await?;
+
+ // Nothing to compare against when the scope sets no threshold, so the read is skipped
+ // rather than fetched and ignored.
+ let decline_count = if settings.connector_decline_threshold.is_some() {
+ read_counter(state, rollout_scope, UcsFailureClass::ConnectorDecline).await?
+ } else {
+ 0
+ };
+
+ Ok(ScopeCounters {
+ count,
+ exceeded: exceeds_threshold(count, settings.kill_switch_threshold),
+ decline_count,
+ decline_exceeded: settings
+ .connector_decline_threshold
+ .is_some_and(|threshold| exceeds_threshold(decline_count, threshold)),
+ })
+}
+
/// Whether the kill switch should divert this scope to shadow mode.
///
/// Checks: per-scope `kill_switch_enabled` from RolloutConfig must be true. Then reads the
@@ -60,29 +109,54 @@ fn rollout_scope_in(key_or_scope: &str) -> &str {
pub async fn is_kill_switched(
state: &SessionState,
rollout_scope: &str,
- kill_switch_enabled: bool,
- kill_switch_threshold: u64,
+ settings: RolloutSettings,
) -> bool {
+ let kill_switch_enabled = settings.kill_switch_enabled;
+ let kill_switch_threshold = settings.kill_switch_threshold;
+
if kill_switch_enabled {
- match read_counter(state, rollout_scope).await {
- Ok(count) => {
- let exceeded = exceeds_threshold(count, kill_switch_threshold);
- if exceeded {
- logger::debug!(
+ match read_counters(state, rollout_scope, &settings).await {
+ Ok(ScopeCounters {
+ count,
+ exceeded,
+ decline_count,
+ decline_exceeded,
+ }) => {
+ // Only when it matters. This runs on every UCS call, and the counter's
+ // value is already reported by UCS_KILL_SWITCH_COUNTER_INCREMENTED at the
+ // moment it changes; logging every read would re-state that at the highest
+ // frequency in the module.
+ // Both can be over at once, so the log names each independently rather
+ // than picking one `failure_class` and hiding the other.
+ if exceeded || decline_exceeded {
+ logger::warn!(
rollout_scope = %rollout_scope,
- count = count,
+ kill_switch_enabled = kill_switch_enabled,
+ redis_count = count,
threshold = kill_switch_threshold,
- "ucs_kill_switch: counter exceeds threshold, routing to shadow"
+ integration_exceeded = exceeded,
+ decline_count = decline_count,
+ connector_decline_threshold = ?settings.connector_decline_threshold,
+ decline_exceeded = decline_exceeded,
+ tripped = true,
+ request_id = ?state.request_id,
+ "UCS_KILL_SWITCH_COUNTER_EXCEEDS_THRESHOLD"
);
}
- exceeded
+ exceeded || decline_exceeded
}
// Fails closed: the scope goes to shadow when Redis cannot answer.
Err(error) => {
+ // Fails closed: the scope goes to shadow. Named so an alert can catch a
+ // Redis outage diverting traffic, which no counter or metric would show.
logger::error!(
?error,
rollout_scope = %rollout_scope,
- "ucs_kill_switch: counter unreadable, routing to shadow"
+ kill_switch_enabled = kill_switch_enabled,
+ threshold = kill_switch_threshold,
+ tripped = true,
+ request_id = ?state.request_id,
+ "UCS_KILL_SWITCH_COUNTER_UNREADABLE"
);
true
}
@@ -102,18 +176,53 @@ pub async fn is_kill_switched(
async fn read_counter(
state: &SessionState,
rollout_scope: &str,
+ failure_class: UcsFailureClass,
) -> error_stack::Result<u64, storage_impl::errors::RedisError> {
let key: redis_interface::RedisKey = counter_key(rollout_scope).as_str().into();
let count: u64 = state
.store
.get_redis_conn()?
- .get_hash_field::<Option<u64>>(&key, COUNTER_FIELD)
+ .get_hash_field::<Option<u64>>(&key, failure_class.counter_field())
.await?
.unwrap_or(0);
Ok(count)
}
+/// The scope's kill switch settings, resolved once by the gate and carried to the failure
+/// path so a failure counts against the same threshold the gate used.
+#[derive(Debug, Clone)]
+pub struct RolloutSettings {
+ pub execution_mode: ExecutionMode,
+ pub kill_switch_enabled: bool,
+ pub kill_switch_threshold: u64,
+ /// `None` means connector declines never trip this scope.
+ pub connector_decline_threshold: Option<u64>,
+ /// The scope the gate read this config from, carried rather than rebuilt at the failure
+ /// path. A payment's later calls run under a different flow (`CreateConnectorCustomer`
+ /// inherits the Authorize decision without gating for itself), so rebuilding the scope
+ /// from the failing call's own flow names a key nothing ever reads: it would accumulate
+ /// a counter, borrow this scope's thresholds, and divert nothing.
+ ///
+ /// `None` on paths no gate governs, where a failure counts against nothing.
+ pub rollout_scope: Option<String>,
+}
+
+impl RolloutSettings {
+ /// Settings under which the kill switch can never divert this call: used where no
+ /// rollout config governs it, i.e. a shadow run or a path the gate does not gate, so
+ /// nothing ever reads the counter. `kill_switch_enabled: false` here states a fact.
+ pub fn without_kill_switch(execution_mode: ExecutionMode) -> Self {
+ Self {
+ execution_mode,
+ kill_switch_enabled: false,
+ kill_switch_threshold: 1,
+ connector_decline_threshold: None,
+ rollout_scope: None,
+ }
+ }
+}
+
/// What a failing UCS call was for. A struct because transposing two of six positional strings
/// would key trips under the wrong scope.
pub struct UcsFailureContext<'a> {
@@ -125,10 +234,52 @@ pub struct UcsFailureContext<'a> {
pub payment_method_type: Option<common_enums::PaymentMethodType>,
}
+/// Which threshold a failure is measured against. A connector decline is usually the
+/// issuer's verdict and identical on the direct path, so it is counted separately from
+/// everything else.
+#[derive(Debug, Clone, Copy, PartialEq, Eq, strum::Display)]
+#[strum(serialize_all = "snake_case")]
+pub enum UcsFailureClass {
+ /// The connector refused the payment: a business outcome, the same on either path.
+ ConnectorDecline,
+ /// Anything else: transport, integration or request-construction failure, on either
+ /// side of the gRPC call. Not necessarily UCS's fault.
+ IntegrationFailure,
+}
+
/// A failure that qualifies to increment the counter, and the scope it targets.
struct TrippableFailure {
rollout_scope: String,
reason: UcsKillSwitchReason,
+ failure_class: UcsFailureClass,
+ /// The threshold this failure is measured against: `connector_decline_threshold` for a
+ /// decline, `kill_switch_threshold` otherwise.
+ threshold: u64,
+ kill_switch_enabled: bool,
+}
+
+/// Records a connector decline: UCS answered gRPC OK with a connector 2xx, and the
+/// connector still refused the payment.
+///
+/// Separate entry point from [`record_failure`] because there is no
+/// `UnifiedConnectorServiceError` to classify on this path — the refusal arrives as
+/// `router_data.response` being `Err`. Counts only when the scope sets
+/// `connector_decline_threshold`.
+pub async fn record_decline(
+ state: &SessionState,
+ context: UcsFailureContext<'_>,
+ settings: RolloutSettings,
+) {
+ if let Some(failure) = trippable_failure_for_reason(
+ state,
+ &context,
+ settings,
+ UcsKillSwitchReason::ConnectorDeclined,
+ )
+ .await
+ {
+ record_trippable_failure(state, &failure, &context, None).await;
+ }
}
/// Records a qualifying UCS failure by incrementing its scope's counter.
@@ -137,11 +288,11 @@ struct TrippableFailure {
pub async fn record_failure(
state: &SessionState,
context: UcsFailureContext<'_>,
- execution_mode: ExecutionMode,
+ settings: RolloutSettings,
error: &UnifiedConnectorServiceError,
) {
- if let Some(failure) = trippable_failure(state, &context, execution_mode, error).await {
- record_trippable_failure(state, &failure, &context, error).await;
+ if let Some(failure) = trippable_failure(state, &context, settings, error).await {
+ record_trippable_failure(state, &failure, &context, Some(error)).await;
}
}
@@ -150,18 +301,31 @@ async fn record_trippable_failure(
state: &SessionState,
failure: &TrippableFailure,
context: &UcsFailureContext<'_>,
- error: &UnifiedConnectorServiceError,
+ error: Option<&UnifiedConnectorServiceError>,
) {
metrics::UCS_KILL_SWITCH_FAILURE.add(
1,
router_env::metric_attributes!(
("connector", context.connector_name.to_string()),
("flow", context.flow_name.to_string()),
- ("reason", failure.reason.to_string())
+ ("reason", failure.reason.to_string()),
+ ("failure_class", failure.failure_class.to_string()),
+ (
+ "kill_switch_enabled",
+ failure.kill_switch_enabled.to_string()
+ )
),
);
- let outcome = increment_counter(state, failure, context).await;
+ let (outcome, redis_count) = increment_counter(state, failure, context).await;
+
+ // Everything an alert needs from one line: scope, threshold, resulting counter,
+ // and whether that tips the scope into shadow.
+ // A counter over its threshold on a scope with the switch disabled diverts nothing,
+ // so it is not "tripped". Without this an alert on tripped=true fires for scopes that
+ // can never divert, which is most of them.
+ let tripped = failure.kill_switch_enabled
+ && redis_count.is_some_and(|count| exceeds_threshold(count, failure.threshold));
logger::warn!(
rollout_scope = %failure.rollout_scope,
@@ -169,9 +333,15 @@ async fn record_trippable_failure(
connector = %context.connector_name,
flow = %context.flow_name,
payment_method = %context.payment_method,
+ payment_method_type = ?context.payment_method_type,
payment_id = %context.payment_id,
request_id = ?state.request_id,
reason = %failure.reason,
+ failure_class = %failure.failure_class,
+ kill_switch_enabled = failure.kill_switch_enabled,
+ threshold = failure.threshold,
+ redis_count = ?redis_count,
+ tripped = tripped,
outcome = %outcome,
ucs_error = ?error,
"UCS_KILL_SWITCH_COUNTER_INCREMENTED"
@@ -183,26 +353,52 @@ async fn record_trippable_failure(
async fn trippable_failure(
state: &SessionState,
context: &UcsFailureContext<'_>,
- execution_mode: ExecutionMode,
+ settings: RolloutSettings,
error: &UnifiedConnectorServiceError,
+) -> Option<TrippableFailure> {
+ let reason = error.ucs_kill_switch_reason()?;
+ trippable_failure_for_reason(state, context, settings, reason).await
+}
+
+/// Shared core: whether this scope can trip at all, which threshold applies, and the
+/// scope's config for the log line.
+async fn trippable_failure_for_reason(
+ state: &SessionState,
+ context: &UcsFailureContext<'_>,
+ settings: RolloutSettings,
+ reason: UcsKillSwitchReason,
) -> Option<TrippableFailure> {
// Only the path serving merchant traffic can trip, and only a connector that has a direct
// integration to fall back to. `&&` keeps the cheap check first.
- let scope_can_trip = matches!(execution_mode, ExecutionMode::Primary)
+ let scope_can_trip = matches!(settings.execution_mode, ExecutionMode::Primary)
&& !is_ucs_only_connector(state, context.connector_name).await;
+ // Only a connector 2xx carrying a refusal is a decline. A connector 4xx/5xx
+ // (`ConnectorRejected`) stays on `kill_switch_threshold` as before: the status code
+ // alone cannot separate a genuine decline from a request UCS built wrongly.
+ let failure_class = match reason {
+ UcsKillSwitchReason::ConnectorDeclined => UcsFailureClass::ConnectorDecline,
+ _ => UcsFailureClass::IntegrationFailure,
+ };
+
+ // The scope and thresholds are the gate's own, carried on the request. Rebuilding the
+ // scope here from this call's flow would name a different key than the gate read, and
+ // re-reading the config could see a different value than the gate used.
scope_can_trip
- .then(|| error.ucs_kill_switch_reason())
+ .then_some(match failure_class {
+ // Declines only count when the scope opts in with `connector_decline_threshold`;
+ // existing configs are unaffected until updated.
+ UcsFailureClass::ConnectorDecline => settings.connector_decline_threshold,
+ UcsFailureClass::IntegrationFailure => Some(settings.kill_switch_threshold),
+ })
.flatten()
- .map(|reason| TrippableFailure {
- rollout_scope: build_merchant_rollout_scope(
- context.merchant_id,
- context.connector_name,
- context.flow_name,
- context.payment_method,
- context.payment_method_type,
- ),
+ .zip(settings.rollout_scope.clone())
+ .map(|(threshold, rollout_scope)| TrippableFailure {
+ rollout_scope,
reason,
+ failure_class,
+ threshold,
+ kill_switch_enabled: settings.kill_switch_enabled,
})
}
@@ -234,34 +430,45 @@ async fn increment_counter(
state: &SessionState,
failure: &TrippableFailure,
context: &UcsFailureContext<'_>,
-) -> IncrementOutcome {
- match write_counter(state, &failure.rollout_scope).await {
+) -> (IncrementOutcome, Option<u64>) {
+ match write_counter(state, &failure.rollout_scope, failure.failure_class).await {
Ok(counts) => {
- metrics::UCS_KILL_SWITCH_TRIPPED.add(
- 1,
- router_env::metric_attributes!(
- ("connector", context.connector_name.to_string()),
- ("flow", context.flow_name.to_string()),
- ("reason", failure.reason.to_string())
- ),
- );
-
- logger::info!(
- rollout_scope = %failure.rollout_scope,
- count = ?counts,
- "ucs_kill_switch: counter incremented"
- );
+ // HINCRBY returns the value of each field after the increment; this call
+ // increments exactly one field.
+ let redis_count = counts.first().and_then(|count| u64::try_from(*count).ok());
+
+ // Only when the counter reaches the threshold on a scope that can actually
+ // divert. Previously this fired on every increment, which made it a duplicate
+ // of UCS_KILL_SWITCH_FAILURE and meant nothing counted actual trips.
+ if failure.kill_switch_enabled
+ && redis_count.is_some_and(|count| exceeds_threshold(count, failure.threshold))
+ {
+ metrics::UCS_KILL_SWITCH_TRIPPED.add(
+ 1,
+ router_env::metric_attributes!(
+ ("connector", context.connector_name.to_string()),
+ ("flow", context.flow_name.to_string()),
+ ("reason", failure.reason.to_string()),
+ ("failure_class", failure.failure_class.to_string())
+ ),
+ );
+ }
- IncrementOutcome::Incremented
+ (IncrementOutcome::Incremented, redis_count)
}
Err(error) => {
+ // The counter did not move, so this failure does not count toward the
+ // threshold: the scope is silently less protected than configured.
logger::error!(
?error,
rollout_scope = %failure.rollout_scope,
- "ucs_kill_switch: could not increment counter"
+ connector = %context.connector_name,
+ flow = %context.flow_name,
+ threshold = failure.threshold,
+ "UCS_KILL_SWITCH_COUNTER_WRITE_FAILED"
);
- IncrementOutcome::WriteFailed
+ (IncrementOutcome::WriteFailed, None)
}
}
}
@@ -272,12 +479,13 @@ async fn increment_counter(
async fn write_counter(
state: &SessionState,
rollout_scope: &str,
+ failure_class: UcsFailureClass,
) -> error_stack::Result<Vec<usize>, storage_impl::errors::RedisError> {
let conn = state.store.get_redis_conn()?;
let key: redis_interface::RedisKey = counter_key(rollout_scope).as_str().into();
let result = conn
- .increment_fields_in_hash(&key, &[(COUNTER_FIELD, 1)])
+ .increment_fields_in_hash(&key, &[(failure_class.counter_field(), 1)])
.await?;
conn.set_expiry(&key, consts::UCS_KILL_SWITCH_TTL_IN_SECONDS)
@@ -301,6 +509,13 @@ pub struct KillSwitchStatusResponse {
pub counter: u64,
/// `None` when no `RolloutConfig` exists for this scope — falls back to trip-on-first-failure.
pub threshold: Option<u64>,
+ /// Connector declines, counted separately from `counter` and measured against
+ /// `connector_decline_threshold`.
+ pub decline_counter: u64,
+ /// `None` when the scope does not set one, in which case declines never trip it.
+ pub connector_decline_threshold: Option<u64>,
+ /// True when either counter has reached its own threshold — the same condition the gate
+ /// diverts on.
pub tripped: bool,
}
@@ -345,10 +560,11 @@ pub async fn trip_status(
) -> errors::RouterResponse<KillSwitchStatusResponse> {
let rollout_scope = rollout_scope_in(&key_or_scope);
- let counter_value: u64 = read_counter(&state, rollout_scope)
- .await
- .change_context(errors::ApiErrorResponse::InternalServerError)
- .attach_printable("Failed to read the UCS kill switch counter")?;
+ let counter_value: u64 =
+ read_counter(&state, rollout_scope, UcsFailureClass::IntegrationFailure)
+ .await
+ .change_context(errors::ApiErrorResponse::InternalServerError)
+ .attach_printable("Failed to read the UCS kill switch counter")?;
// Fetch the kill_switch_threshold from the RolloutConfig for this scope.
// Uses the scope-level config key (without org prefix) since trip_status
@@ -358,7 +574,7 @@ pub async fn trip_status(
consts::UCS_ROLLOUT_PERCENT_CONFIG_PREFIX,
rollout_scope
);
- let threshold: Option<u64> = state
+ let rollout_config: Option<(u64, Option<u64>)> = state
.store
.find_config_by_key_unwrap_or(
&config_key,
@@ -378,18 +594,36 @@ pub async fn trip_status(
})
.ok()
})
- .map(|rc| rc.kill_switch_threshold);
+ .map(|rc| (rc.kill_switch_threshold, rc.connector_decline_threshold));
+
+ let (threshold, connector_decline_threshold) = match rollout_config {
+ Some((integration, decline)) => (Some(integration), decline),
+ None => (None, None),
+ };
+
+ // Only read when something can come of it, matching the gate.
+ let decline_counter = if connector_decline_threshold.is_some() {
+ read_counter(&state, rollout_scope, UcsFailureClass::ConnectorDecline)
+ .await
+ .change_context(errors::ApiErrorResponse::InternalServerError)
+ .attach_printable("Failed to read the UCS kill switch decline counter")?
+ } else {
+ 0
+ };
let tripped = match threshold {
Some(t) => exceeds_threshold(counter_value, t),
None => counter_value > 0,
- };
+ } || connector_decline_threshold
+ .is_some_and(|threshold| exceeds_threshold(decline_counter, threshold));
Ok(crate::services::ApplicationResponse::Json(
KillSwitchStatusResponse {
rollout_scope: rollout_scope.to_string(),
counter: counter_value,
threshold,
+ decline_counter,
+ connector_decline_threshold,
tripped,
},
))
@@ -400,6 +634,9 @@ mod tests {
use common_enums::{PaymentMethod, PaymentMethodType};
use super::*;
+ // Production code carries the scope from the gate rather than rebuilding it; the tests
+ // still construct scopes directly to assert on their shape.
+ use crate::core::unified_connector_service::build_merchant_rollout_scope;
/// A connector's own answer, arriving through UCS.
fn connector_error(status_code: u16) -> UnifiedConnectorServiceError {
@@ -482,7 +719,7 @@ mod tests {
for error in cases {
assert_eq!(
error.ucs_kill_switch_reason(),
- Some(UcsKillSwitchReason::ConnectorOutcome),
+ Some(UcsKillSwitchReason::ConnectorRejected),
"{error:?}"
);
}
@@ -551,6 +788,27 @@ mod tests {
assert!(!key.starts_with(consts::UCS_ROLLOUT_PERCENT_CONFIG_PREFIX));
}
+ /// The whole point of a separate `connector_decline_threshold`: a decline must not be
+ /// measured against a count that integration failures contributed to. Sharing one field
+ /// would make `connector_decline_threshold: N` mean "N failures of any kind".
+ #[test]
+ fn each_failure_class_counts_into_its_own_field() {
+ assert_ne!(
+ UcsFailureClass::ConnectorDecline.counter_field(),
+ UcsFailureClass::IntegrationFailure.counter_field()
+ );
+ }
+
+ /// Scopes in flight already hold their count under `counter`. Renaming that field would
+ /// silently reset every live counter on deploy, un-tripping scopes that had tripped.
+ #[test]
+ fn integration_failures_keep_the_pre_existing_field_name() {
+ assert_eq!(
+ UcsFailureClass::IntegrationFailure.counter_field(),
+ "counter"
+ );
+ }
+
#[test]
fn failure_reasons_have_distinct_tags() {
let tags = [
@@ -560,7 +818,7 @@ mod tests {
UcsKillSwitchReason::UcsFlowUnsupported.to_string(),
UcsKillSwitchReason::UcsInternalError.to_string(),
UcsKillSwitchReason::UcsUnreachable.to_string(),
- UcsKillSwitchReason::ConnectorOutcome.to_string(),
+ UcsKillSwitchReason::ConnectorRejected.to_string(),
];
let unique: std::collections::HashSet<_> = tags.iter().collect();
diff --git a/crates/router/src/core/webhooks/gateway.rs b/crates/router/src/core/webhooks/gateway.rs
index 3735b76324..1797e2fcfa 100644
--- a/crates/router/src/core/webhooks/gateway.rs
+++ b/crates/router/src/core/webhooks/gateway.rs
@@ -884,6 +884,8 @@ fn build_ucs_headers_builder(
.unwrap_or_else(|| consts::PROFILE_ID_UNAVAILABLE.clone());
ctx.state
.get_grpc_headers_ucs(mode)
+ .payment_method(None)
+ .payment_method_type(None)
.lineage_ids(LineageIds::new(merchant_id, profile_id))
.external_vault_proxy_metadata(None)
.merchant_reference_id(None)