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(routing): add eligibility filtering for fallback connectors in hybrid routing (#14628)

Gaurav Rawatc41c9e22ec00
diff --git a/crates/router/src/core/payments.rs b/crates/router/src/core/payments.rs
index f4edebde3e..7397d8873e 100644
--- a/crates/router/src/core/payments.rs
+++ b/crates/router/src/core/payments.rs
@@ -12121,6 +12121,7 @@ where
async move {
static_dynamic_routing_v1_for_payments(
state_ref,
+ processor.get_key_store(),
dimensions,
business_profile,
txn_data,
@@ -13117,6 +13118,7 @@ pub async fn route_connector_v2_for_payments(
#[allow(clippy::too_many_arguments)]
pub async fn static_dynamic_routing_v1_for_payments(
state: &SessionState,
+ key_store: &domain::MerchantKeyStore,
dimensions: &DimensionsWithProcessorAndProviderMerchantIdAndProfileId,
business_profile: &domain::Profile,
payment_dsl_input: core_routing::PaymentsDslInput<'_>,
@@ -13135,6 +13137,7 @@ pub async fn static_dynamic_routing_v1_for_payments(
let (connectors, routing_approach) = routing::perform_hybrid_routing_if_enabled(
state,
+ key_store,
business_profile,
dimensions,
&payment_dsl_input,
diff --git a/crates/router/src/core/payments/routing.rs b/crates/router/src/core/payments/routing.rs
index b7d7244be2..82939d0980 100644
--- a/crates/router/src/core/payments/routing.rs
+++ b/crates/router/src/core/payments/routing.rs
@@ -1620,7 +1620,8 @@ impl HybridRoutingStage {
OpenRouterDecideGatewayRequest::construct_sr_request(
input.payment_dsl_input.payment_attempt,
- input.static_connectors.to_vec(),
+ // Use the same eligibility-filtered fallbacks as the static request.
+ input.fallback_config.to_vec(),
Some(or_types::RankingAlgorithm::SrBasedRouting),
preferred_connector,
)
@@ -1728,6 +1729,7 @@ fn profile_has_active_routing_algorithm(business_profile: &domain::Profile) -> b
#[cfg(feature = "v1")]
pub async fn perform_hybrid_routing_if_enabled(
state: &SessionState,
+ key_store: &domain::MerchantKeyStore,
business_profile: &domain::Profile,
dimensions: &dimension_state::DimensionsWithProcessorAndProviderMerchantIdAndProfileId,
payment_dsl_input: &routing::PaymentsDslInput<'_>,
@@ -1751,17 +1753,6 @@ pub async fn perform_hybrid_routing_if_enabled(
_ => None,
};
- let input = HybridRoutingInput {
- state,
- business_profile,
- payment_dsl_input,
- backend_input,
- fallback_config,
- static_connectors,
- static_approach: static_approach.clone(),
- preferred_connector,
- };
-
// Flag-aware like every other consumer: with static_routing_enabled off the profile is
// Hyperswitch-routed, so this stage must not run.
let is_decision_engine_cutover_enabled =
@@ -1772,16 +1763,37 @@ pub async fn perform_hybrid_routing_if_enabled(
// algorithm is the normal state and must not skip evaluation; for every other profile
// there is nothing to evaluate against, so the DE call is skipped.
if is_decision_engine_cutover_enabled {
- let hybrid_stage_outcome = stage
- .route(input)
+ // Filter fallbacks by payment eligibility before sending them to Decision Engine.
+ let hybrid_stage_outcome = async {
+ let eligible_fallback = filter_fallback_based_on_eligibility(
+ state,
+ key_store,
+ fallback_config,
+ &routing::TransactionData::Payment(payment_dsl_input.clone()),
+ business_profile,
+ )
.await
.inspect_err(|error| {
- logger::error!(
- error=?error,
- "euclid: hybrid routing failed"
- );
- })
- .unwrap_or_else(|_| RoutingConnectorOutcomeWithApproach::empty());
+ logger::error!(error=?error, "euclid: fallback eligibility failed before hybrid routing");
+ })?;
+ let input = HybridRoutingInput {
+ state,
+ business_profile,
+ payment_dsl_input,
+ backend_input,
+ fallback_config: &eligible_fallback,
+ static_connectors,
+ static_approach: static_approach.clone(),
+ preferred_connector,
+ };
+
+ stage.route(input).await
+ }
+ .await
+ .inspect_err(|error| {
+ logger::error!(error=?error, "euclid: hybrid routing failed");
+ })
+ .unwrap_or_else(|_| RoutingConnectorOutcomeWithApproach::empty());
let selected_source = if hybrid_stage_outcome.connectors.is_empty() {
"hyperswitch_static"
@@ -2624,6 +2636,32 @@ fn update_eligible_connectors_for_installments(
.or(installment_supported_connectors)
}
+/// Filters active fallbacks by payment eligibility while preserving their configured order.
+#[cfg(feature = "v1")]
+pub async fn filter_fallback_based_on_eligibility(
+ state: &SessionState,
+ key_store: &domain::MerchantKeyStore,
+ fallback_config: &[routing_types::RoutableConnectorChoice],
+ transaction_data: &routing::TransactionData<'_>,
+ business_profile: &domain::Profile,
+) -> RoutingResult<Vec<routing_types::RoutableConnectorChoice>> {
+ let active_mca_ids =
+ get_active_merchant_connector_accounts(state, key_store, business_profile.get_id())
+ .await?
+ .get_ids();
+
+ perform_eligibility_analysis(
+ state,
+ key_store,
+ fallback_config.to_vec(),
+ transaction_data,
+ None,
+ &active_mca_ids,
+ business_profile,
+ )
+ .await
+}
+
pub async fn perform_eligibility_analysis(
state: &SessionState,
key_store: &domain::MerchantKeyStore,