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

refactor(euclid): default fallback to hs routing result for 4xx from DE service (#10358)

Prajjwal Kumar9d39e28bda54
diff --git a/crates/router/src/core/payments/routing.rs b/crates/router/src/core/payments/routing.rs
index c773dccc8d..3fd58aa953 100644
--- a/crates/router/src/core/payments/routing.rs
+++ b/crates/router/src/core/payments/routing.rs
@@ -488,21 +488,35 @@ pub async fn perform_static_routing_v1(
.get_default_fallback_list_of_connector_under_profile()
.change_context(errors::RoutingError::FallbackConfigFetchFailed);
};
+
+ let fallback_config = get_merchant_fallback_config().await?;
+
let algorithm_id = if let Some(id) = algorithm_id {
id
} else {
- let fallback_config = get_merchant_fallback_config().await?;
logger::debug!("euclid_routing: active algorithm isn't present, default falling back");
return Ok((fallback_config, None));
};
- let cached_algorithm = ensure_algorithm_cached_v1(
+
+ let cached_algorithm = match ensure_algorithm_cached_v1(
state,
merchant_id,
algorithm_id,
business_profile.get_id(),
&api_enums::TransactionType::from(transaction_data),
)
- .await?;
+ .await
+ {
+ Ok(algo) => algo,
+ Err(err) => {
+ logger::error!(
+ error=?err,
+ "euclid_routing: ensure_algorithm_cached failed, falling back to merchant default connectors"
+ );
+
+ return Ok((fallback_config, None));
+ }
+ };
let backend_input = match transaction_data {
routing::TransactionData::Payment(payment_data) => make_dsl_input(payment_data)?,
@@ -535,7 +549,7 @@ pub async fn perform_static_routing_v1(
backend_input.clone(),
business_profile,
payment_id,
- get_merchant_fallback_config().await?,
+ fallback_config,
)
.await
.map_err(|e|
diff --git a/crates/router/src/core/payments/routing/utils.rs b/crates/router/src/core/payments/routing/utils.rs
index fa44c71599..30d0670262 100644
--- a/crates/router/src/core/payments/routing/utils.rs
+++ b/crates/router/src/core/payments/routing/utils.rs
@@ -713,13 +713,25 @@ pub fn compare_and_log_result<T: RoutingEq<T> + Serialize>(
result: Vec<T>,
flow: String,
) {
- let is_equal = de_result
- .iter()
- .zip(result.iter())
- .all(|(a, b)| T::is_equal(a, b));
+ let is_equal = if de_result.is_empty() && result.is_empty() {
+ true
+ } else {
+ de_result
+ .iter()
+ .zip(result.iter())
+ .all(|(a, b)| T::is_equal(a, b))
+ };
let is_equal_in_length = de_result.len() == result.len();
- router_env::logger::debug!(routing_flow=?flow, is_equal=?is_equal, is_equal_length=?is_equal_in_length, de_response=?to_json_string(&de_result), hs_response=?to_json_string(&result), "decision_engine_euclid");
+
+ router_env::logger::debug!(
+ routing_flow=?flow,
+ is_equal=?is_equal,
+ is_equal_length=?is_equal_in_length,
+ de_response=?to_json_string(&de_result),
+ hs_response=?to_json_string(&result),
+ "decision_engine_euclid"
+ );
}
pub trait RoutingEq<T> {
@@ -802,6 +814,12 @@ pub fn convert_backend_input_to_routing_eval(
Some(ValueType::EnumVariant(auth_type.to_string())),
);
}
+ if let Some(extended_bin) = input.payment.extended_card_bin {
+ params.insert(
+ "extended_card_bin".to_string(),
+ Some(ValueType::StrValue(extended_bin)),
+ );
+ }
if let Some(bin) = input.payment.card_bin {
params.insert("card_bin".to_string(), Some(ValueType::StrValue(bin)));
}
@@ -1477,7 +1495,10 @@ pub async fn select_routing_result<T>(
business_profile: &business_profile::Profile,
hyperswitch_result: T,
de_result: T,
-) -> T {
+) -> T
+where
+ T: Clone + IntoIterator,
+{
let routing_result_source: Option<api_routing::RoutingResultSource> = state
.store
.find_config_by_key(&format!(
@@ -1486,15 +1507,33 @@ pub async fn select_routing_result<T>(
))
.await
.map(|c| c.config.parse_enum("RoutingResultSource").ok())
- .unwrap_or(None); //Ignore errors so that we can use the hyperswitch result as a fallback
+ .unwrap_or(None);
+
if let Some(api_routing::RoutingResultSource::DecisionEngine) = routing_result_source {
- logger::debug!(business_profile_id=?business_profile.get_id(), "Using Decision Engine routing result");
- de_result
+ logger::debug!(
+ business_profile_id=?business_profile.get_id(),
+ "decision_engine_euclid: Using Decision Engine routing result"
+ );
+
+ let is_de_result_empty = de_result.clone().into_iter().next().is_none();
+ if is_de_result_empty {
+ logger::debug!(
+ business_profile_id=?business_profile.get_id(),
+ "decision_engine_euclid: DE result empty, falling back to Hyperswitch result"
+ );
+ hyperswitch_result
+ } else {
+ de_result
+ }
} else {
- logger::debug!(business_profile_id=?business_profile.get_id(), "Using Hyperswitch routing result");
+ logger::debug!(
+ business_profile_id=?business_profile.get_id(),
+ "decision_engine_euclid: Using Hyperswitch routing result"
+ );
hyperswitch_result
}
}
+
pub trait DecisionEngineErrorsInterface {
fn get_error_message(&self) -> String;
fn get_error_code(&self) -> String;