Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
feat(core): Implement UCS kill switch for emergency fallback (#8651)
Uzair Khan0c5bbad9c2bd
diff --git a/crates/router/src/consts.rs b/crates/router/src/consts.rsindex f9d6daa53e..a6c0954f8f 100644--- a/crates/router/src/consts.rs+++ b/crates/router/src/consts.rs@@ -309,7 +309,10 @@ pub const PSD2_COUNTRIES: [Country; 27] = [];// Rollout percentage config prefix-pub const UCS_ROLLOUT_PERCENT_CONFIG_PREFIX: &str = "UCS_ROLLOUT_CONFIG";+pub const UCS_ROLLOUT_PERCENT_CONFIG_PREFIX: &str = "ucs_rollout_config";++// UCS feature enabled config+pub const UCS_ENABLED: &str = "ucs_enabled";/// Header value indicating that signature-key-based authentication is used.pub const UCS_AUTH_SIGNATURE_KEY: &str = "signature-key";diff --git a/crates/router/src/core/payments.rs b/crates/router/src/core/payments.rsindex 0ed5dc0609..cc6f3384a2 100644--- a/crates/router/src/core/payments.rs+++ b/crates/router/src/core/payments.rs@@ -4482,22 +4482,10 @@ whereOk(router_data)} else {- let router_data = if should_continue_further {- router_data- .decide_flows(- state,- &connector,- call_connector_action,- connector_request,- business_profile,- header_payload.clone(),- return_raw_connector_response,- )- .await- } else {- Ok(router_data)- }?;- Ok(router_data)+ Err(+ errors::ApiErrorResponse::InternalServerError+ )+ .attach_printable("Unified connector service is down and traditional connector service fallback is not implemented")}}).awaitdiff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rsindex d6ce585829..4a023f7d8c 100644--- a/crates/router/src/core/payments/helpers.rs+++ b/crates/router/src/core/payments/helpers.rs@@ -2037,6 +2037,27 @@ pub fn decide_payment_method_retrieval_action(}}+pub async fn is_ucs_enabled(state: &SessionState, config_key: &str) -> bool {+ let db = state.store.as_ref();+ let is_enabled = db+ .find_config_by_key_unwrap_or(config_key, Some("false".to_string()))+ .await+ .map_err(|error| {+ logger::error!(+ ?error,+ "Failed to fetch `{config_key}` UCS enabled config from DB"+ );+ })+ .and_then(|config| {+ config.config.parse::<bool>().map_err(|error| {+ logger::error!(?error, "Failed to parse `{config_key}` UCS enabled config");+ })+ })+ .unwrap_or(false);++ is_enabled+}+pub async fn should_execute_based_on_rollout(state: &SessionState,config_key: &str,diff --git a/crates/router/src/core/unified_connector_service.rs b/crates/router/src/core/unified_connector_service.rsindex 14836ff20c..8c246facaf 100644--- a/crates/router/src/core/unified_connector_service.rs+++ b/crates/router/src/core/unified_connector_service.rs@@ -22,7 +22,9 @@ use crate::{consts,core::{errors::RouterResult,- payments::helpers::{should_execute_based_on_rollout, MerchantConnectorAccountType},+ payments::helpers::{+ is_ucs_enabled, should_execute_based_on_rollout, MerchantConnectorAccountType,+ },utils::get_flow_name,},routes::SessionState,@@ -36,6 +38,16 @@ pub async fn should_call_unified_connector_service<F: Clone, T>(merchant_context: &MerchantContext,router_data: &RouterData<F, T, PaymentsResponseData>,) -> RouterResult<bool> {+ if state.grpc_client.unified_connector_service_client.is_none() {+ return Ok(false);+ }++ let ucs_config_key = consts::UCS_ENABLED;++ if !is_ucs_enabled(state, ucs_config_key).await {+ return Ok(false);+ }+let merchant_id = merchant_context.get_merchant_account().get_id()@@ -55,7 +67,7 @@ pub async fn should_call_unified_connector_service<F: Clone, T>();let should_execute = should_execute_based_on_rollout(state, &config_key).await?;- Ok(should_execute && state.grpc_client.unified_connector_service_client.is_some())+ Ok(should_execute)}pub fn build_unified_connector_service_payment_method(