Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions crates/common_enums/src/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8523,6 +8523,7 @@ pub enum RoutingApproach {
DebitRouting,
RuleBasedRouting,
VolumeBasedRouting,
StraightThroughRouting,
#[default]
DefaultFallback,
}
Expand All @@ -8533,6 +8534,7 @@ impl RoutingApproach {
"SR_SELECTION_V3_ROUTING" => Self::SuccessRateExploitation,
"SR_V3_HEDGING" => Self::SuccessRateExploration,
"NTW_BASED_ROUTING" => Self::DebitRouting,
"DEFAULT" => Self::StraightThroughRouting,
_ => Self::DefaultFallback,
}
}
Expand Down
4 changes: 3 additions & 1 deletion crates/diesel_models/src/payment_attempt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,7 @@ pub enum PaymentAttemptUpdate {
tax_amount: Option<MinorUnit>,
updated_by: String,
merchant_connector_id: Option<id_type::MerchantConnectorAccountId>,
routing_approach: Option<storage_enums::RoutingApproach>,
},
AuthenticationTypeUpdate {
authentication_type: storage_enums::AuthenticationType,
Expand Down Expand Up @@ -3088,6 +3089,7 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
tax_amount,
updated_by,
merchant_connector_id,
routing_approach,
} => Self {
payment_token,
modified_at: common_utils::date_time::now(),
Expand Down Expand Up @@ -3146,7 +3148,7 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
issuer_error_code: None,
issuer_error_message: None,
setup_future_usage_applied: None,
routing_approach: None,
routing_approach,
},
PaymentAttemptUpdate::UnresolvedResponseUpdate {
status,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1191,6 +1191,7 @@ pub enum PaymentAttemptUpdate {
tax_amount: Option<MinorUnit>,
updated_by: String,
merchant_connector_id: Option<id_type::MerchantConnectorAccountId>,
routing_approach: Option<storage_enums::RoutingApproach>,
},
AuthenticationTypeUpdate {
authentication_type: storage_enums::AuthenticationType,
Expand Down Expand Up @@ -1227,7 +1228,7 @@ pub enum PaymentAttemptUpdate {
customer_acceptance: Option<pii::SecretSerdeValue>,
connector_mandate_detail: Option<ConnectorMandateReferenceId>,
card_discovery: Option<common_enums::CardDiscovery>,
routing_approach: Option<storage_enums::RoutingApproach>, // where all to add this one
routing_approach: Option<storage_enums::RoutingApproach>,
},
RejectUpdate {
status: storage_enums::AttemptStatus,
Expand Down Expand Up @@ -1413,6 +1414,7 @@ impl PaymentAttemptUpdate {
surcharge_amount,
tax_amount,
merchant_connector_id,
routing_approach,
} => DieselPaymentAttemptUpdate::UpdateTrackers {
payment_token,
connector,
Expand All @@ -1422,6 +1424,7 @@ impl PaymentAttemptUpdate {
tax_amount,
updated_by,
merchant_connector_id,
routing_approach,
},
Self::AuthenticationTypeUpdate {
authentication_type,
Expand Down
3 changes: 2 additions & 1 deletion crates/router/src/core/payment_methods/cards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2845,7 +2845,7 @@ pub async fn list_payment_methods(
payment_intent,
chosen,
};
let result = routing::perform_session_flow_routing(
let (result, routing_approach) = routing::perform_session_flow_routing(
sfr,
&business_profile,
&enums::TransactionType::Payment,
Expand Down Expand Up @@ -3027,6 +3027,7 @@ pub async fn list_payment_methods(
merchant_connector_id: None,
surcharge_amount: None,
tax_amount: None,
routing_approach,
};

state
Expand Down
12 changes: 9 additions & 3 deletions crates/router/src/core/payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7331,6 +7331,10 @@ where
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Failed execution of straight through routing")?;

payment_data.set_routing_approach_in_attempt(Some(
common_enums::RoutingApproach::StraightThroughRouting,
));

if check_eligibility {
let transaction_data = core_routing::PaymentsDslInput::new(
payment_data.get_setup_mandate(),
Expand Down Expand Up @@ -7911,12 +7915,12 @@ pub async fn perform_session_token_routing<F, D>(
state: SessionState,
merchant_context: &domain::MerchantContext,
business_profile: &domain::Profile,
payment_data: &D,
payment_data: &mut D,
connectors: api::SessionConnectorDatas,
) -> RouterResult<api::SessionConnectorDatas>
where
F: Clone,
D: OperationSessionGetters<F>,
D: OperationSessionGetters<F> + OperationSessionSetters<F>,
{
let chosen = connectors.apply_filter_for_session_routing();
let sfr = SessionFlowRoutingInput {
Expand All @@ -7932,7 +7936,7 @@ where
payment_intent: payment_data.get_payment_intent(),
chosen,
};
let result = self_routing::perform_session_flow_routing(
let (result, routing_approach) = self_routing::perform_session_flow_routing(
sfr,
business_profile,
&enums::TransactionType::Payment,
Expand All @@ -7941,6 +7945,8 @@ where
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("error performing session flow routing")?;

payment_data.set_routing_approach_in_attempt(routing_approach);

let final_list = connectors.filter_and_validate_for_session_flow(&result)?;

Ok(final_list)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -880,6 +880,8 @@ impl<F: Clone + Sync> UpdateTracker<F, PaymentData<F>, api::PaymentsRequest> for
.as_ref()
.map(|surcharge_details| surcharge_details.tax_on_surcharge_amount);

let routing_approach = payment_data.payment_attempt.routing_approach;

payment_data.payment_attempt = state
.store
.update_payment_attempt_with_attempt_id(
Expand All @@ -896,6 +898,7 @@ impl<F: Clone + Sync> UpdateTracker<F, PaymentData<F>, api::PaymentsRequest> for
tax_amount,
updated_by: storage_scheme.to_string(),
merchant_connector_id,
routing_approach,
},
storage_scheme,
)
Expand Down
80 changes: 52 additions & 28 deletions crates/router/src/core/payments/routing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,10 @@ pub async fn perform_static_routing_v1(
).unwrap_or_default();

let (routable_connectors, routing_approach) = match cached_algorithm.as_ref() {
CachedAlgorithm::Single(conn) => (vec![(**conn).clone()], None),
CachedAlgorithm::Single(conn) => (
vec![(**conn).clone()],
Some(common_enums::RoutingApproach::StraightThroughRouting),
),
CachedAlgorithm::Priority(plist) => (plist.clone(), None),
CachedAlgorithm::VolumeSplit(splits) => (
perform_volume_split(splits.to_vec())
Expand Down Expand Up @@ -1208,8 +1211,10 @@ pub async fn perform_session_flow_routing(
session_input: SessionFlowRoutingInput<'_>,
business_profile: &domain::Profile,
transaction_type: &api_enums::TransactionType,
) -> RoutingResult<FxHashMap<api_enums::PaymentMethodType, Vec<routing_types::SessionRoutingChoice>>>
{
) -> RoutingResult<(
FxHashMap<api_enums::PaymentMethodType, Vec<routing_types::SessionRoutingChoice>>,
Option<common_enums::RoutingApproach>,
)> {
let mut pm_type_map: FxHashMap<api_enums::PaymentMethodType, FxHashMap<String, api::GetToken>> =
FxHashMap::default();

Expand Down Expand Up @@ -1297,6 +1302,7 @@ pub async fn perform_session_flow_routing(
api_enums::PaymentMethodType,
Vec<routing_types::SessionRoutingChoice>,
> = FxHashMap::default();
let mut final_routing_approach = None;

for (pm_type, allowed_connectors) in pm_type_map {
let euclid_pmt: euclid_enums::PaymentMethodType = pm_type;
Expand All @@ -1315,12 +1321,15 @@ pub async fn perform_session_flow_routing(
profile_id: &profile_id,
};

let routable_connector_choice_option = perform_session_routing_for_pm_type(
&session_pm_input,
transaction_type,
business_profile,
)
.await?;
let (routable_connector_choice_option, routing_approach) =
perform_session_routing_for_pm_type(
&session_pm_input,
transaction_type,
business_profile,
)
.await?;

final_routing_approach = routing_approach;

if let Some(routable_connector_choice) = routable_connector_choice_option {
let mut session_routing_choice: Vec<routing_types::SessionRoutingChoice> = Vec::new();
Expand Down Expand Up @@ -1348,22 +1357,25 @@ pub async fn perform_session_flow_routing(
}
}

Ok(result)
Ok((result, final_routing_approach))
}

#[cfg(feature = "v1")]
async fn perform_session_routing_for_pm_type(
session_pm_input: &SessionRoutingPmTypeInput<'_>,
transaction_type: &api_enums::TransactionType,
_business_profile: &domain::Profile,
) -> RoutingResult<Option<Vec<api_models::routing::RoutableConnectorChoice>>> {
) -> RoutingResult<(
Option<Vec<api_models::routing::RoutableConnectorChoice>>,
Option<common_enums::RoutingApproach>,
)> {
let merchant_id = &session_pm_input.key_store.merchant_id;

let algorithm_id = match session_pm_input.routing_algorithm {
MerchantAccountRoutingAlgorithm::V1(algorithm_ref) => &algorithm_ref.algorithm_id,
};

let chosen_connectors = if let Some(ref algorithm_id) = algorithm_id {
let (chosen_connectors, routing_approach) = if let Some(ref algorithm_id) = algorithm_id {
let cached_algorithm = ensure_algorithm_cached_v1(
&session_pm_input.state.clone(),
merchant_id,
Expand All @@ -1374,23 +1386,35 @@ async fn perform_session_routing_for_pm_type(
.await?;

match cached_algorithm.as_ref() {
CachedAlgorithm::Single(conn) => vec![(**conn).clone()],
CachedAlgorithm::Priority(plist) => plist.clone(),
CachedAlgorithm::VolumeSplit(splits) => perform_volume_split(splits.to_vec())
.change_context(errors::RoutingError::ConnectorSelectionFailed)?,
CachedAlgorithm::Advanced(interpreter) => execute_dsl_and_get_connector_v1(
session_pm_input.backend_input.clone(),
interpreter,
)?,
CachedAlgorithm::Single(conn) => (
vec![(**conn).clone()],
Some(common_enums::RoutingApproach::StraightThroughRouting),
),
CachedAlgorithm::Priority(plist) => (plist.clone(), None),
CachedAlgorithm::VolumeSplit(splits) => (
perform_volume_split(splits.to_vec())
.change_context(errors::RoutingError::ConnectorSelectionFailed)?,
Some(common_enums::RoutingApproach::VolumeBasedRouting),
),
CachedAlgorithm::Advanced(interpreter) => (
execute_dsl_and_get_connector_v1(
session_pm_input.backend_input.clone(),
interpreter,
)?,
Some(common_enums::RoutingApproach::RuleBasedRouting),
),
}
} else {
routing::helpers::get_merchant_default_config(
&*session_pm_input.state.clone().store,
session_pm_input.profile_id.get_string_repr(),
transaction_type,
(
routing::helpers::get_merchant_default_config(
&*session_pm_input.state.clone().store,
session_pm_input.profile_id.get_string_repr(),
transaction_type,
)
.await
.change_context(errors::RoutingError::FallbackConfigFetchFailed)?,
None,
)
.await
.change_context(errors::RoutingError::FallbackConfigFetchFailed)?
};

let mut final_selection = perform_cgraph_filtering(
Expand Down Expand Up @@ -1426,9 +1450,9 @@ async fn perform_session_routing_for_pm_type(
}

if final_selection.is_empty() {
Ok(None)
Ok((None, routing_approach))
} else {
Ok(Some(final_selection))
Ok((Some(final_selection), routing_approach))
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- This file should undo anything in `up.sql`
SELECT 1;
3 changes: 3 additions & 0 deletions migrations/2025-06-27-120507_update_routing_approach/up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-- Your SQL goes here
ALTER TYPE "RoutingApproach"
ADD VALUE 'straight_through_routing';
Loading