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
fix(router): make session token routing merchant-connector-account aware (#12629)
Ayush Anand8577fb99c632
diff --git a/crates/router/src/core/payment_methods/cards.rs b/crates/router/src/core/payment_methods/cards.rsindex e532a8228a..7d3e222143 100644--- a/crates/router/src/core/payment_methods/cards.rs+++ b/crates/router/src/core/payment_methods/cards.rs@@ -3667,10 +3667,18 @@ pub async fn build_merchant_enabled_pms_context(&intermediate.payment_method_type,&skip_pre_routing,) {+ let merchant_connector_id = id_type::MerchantConnectorAccountId::wrap(+ intermediate.merchant_connector_id.clone(),+ )+ .change_context(errors::ApiErrorResponse::InternalServerError)+ .attach_printable(+ "invalid merchant_connector_id received in payment methods list",+ )?;+let connector_data = helpers::get_connector_data_with_token(state,intermediate.connector.to_string(),- None,+ Some(merchant_connector_id),intermediate.payment_method_type,).change_context(errors::ApiErrorResponse::InternalServerError)diff --git a/crates/router/src/core/payments/routing.rs b/crates/router/src/core/payments/routing.rsindex 5a90b08dd0..c6b3d1a106 100644--- a/crates/router/src/core/payments/routing.rs+++ b/crates/router/src/core/payments/routing.rs@@ -112,7 +112,7 @@ pub struct SessionRoutingPmTypeInput<'a> {key_store: &'a domain::MerchantKeyStore,routing_algorithm: &'a MerchantAccountRoutingAlgorithm,backend_input: dsl_inputs::BackendInput,- allowed_connectors: FxHashMap<String, api::GetToken>,+ allowed_connectors: FxHashMap<SessionRoutingConnectorKey, api::GetToken>,profile_id: &'a common_utils::id_type::ProfileId,}@@ -120,12 +120,14 @@ pub struct SessionRoutingPmTypeInput<'a> {pub struct SessionRoutingPmTypeInput<'a> {routing_algorithm: &'a MerchantAccountRoutingAlgorithm,backend_input: dsl_inputs::BackendInput,- allowed_connectors: FxHashMap<String, api::GetToken>,+ allowed_connectors: FxHashMap<SessionRoutingConnectorKey, api::GetToken>,profile_id: &'a common_utils::id_type::ProfileId,}type RoutingResult<O> = oss_errors::CustomResult<O, errors::RoutingError>;+type SessionRoutingConnectorKey = Option<common_utils::id_type::MerchantConnectorAccountId>;+#[cfg(feature = "v1")]#[derive(Debug, serde::Serialize, serde::Deserialize)]#[serde(untagged)]@@ -917,7 +919,7 @@ impl RoutingStage for SessionRoutingStage {Box::pin(async move {let mut pm_type_map: FxHashMap<api_enums::PaymentMethodType,- FxHashMap<String, api::GetToken>,+ FxHashMap<SessionRoutingConnectorKey, api::GetToken>,> = FxHashMap::default();let profile_id = input.business_profile.get_id();@@ -927,7 +929,7 @@ impl RoutingStage for SessionRoutingStage {.entry(connector_data.payment_method_sub_type).or_default().insert(- connector_data.connector.connector_name.to_string(),+ connector_data.connector.merchant_connector_id.clone(),connector_data.connector.get_token.clone(),);}@@ -1047,7 +1049,9 @@ impl RoutingStage for SessionRoutingStage {for selection in routable_connector_choice {let connector_name = selection.connector.to_string();- if let Some(get_token) = allowed_connectors.get(&connector_name) {+ if let Some(get_token) =+ allowed_connectors.get(&selection.merchant_connector_id)+ {let connector_data = api::ConnectorData::get_connector_by_name(&input.state.clone().conf.connectors,&connector_name,@@ -2453,8 +2457,10 @@ pub async fn perform_session_flow_routing<'a>(transaction_type: &api_enums::TransactionType,) -> RoutingResult<FxHashMap<api_enums::PaymentMethodType, Vec<routing_types::SessionRoutingChoice>>>{- let mut pm_type_map: FxHashMap<api_enums::PaymentMethodType, FxHashMap<String, api::GetToken>> =- FxHashMap::default();+ let mut pm_type_map: FxHashMap<+ api_enums::PaymentMethodType,+ FxHashMap<SessionRoutingConnectorKey, api::GetToken>,+ > = FxHashMap::default();let profile_id = business_profile.get_id().clone();@@ -2517,7 +2523,7 @@ pub async fn perform_session_flow_routing<'a>(.entry(connector_data.payment_method_sub_type).or_default().insert(- connector_data.connector.connector_name.to_string(),+ connector_data.connector.merchant_connector_id.clone(),connector_data.connector.get_token.clone(),);}@@ -2557,7 +2563,10 @@ pub async fn perform_session_flow_routing<'a>(for selection in routable_connector_choice {let connector_name = selection.connector.to_string();- if let Some(get_token) = session_pm_input.allowed_connectors.get(&connector_name) {+ if let Some(get_token) = session_pm_input+ .allowed_connectors+ .get(&selection.merchant_connector_id)+ {let connector_data = api::ConnectorData::get_connector_by_name(&state.clone().conf.connectors,&connector_name,@@ -2590,8 +2599,10 @@ pub async fn perform_session_flow_routing(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();+ let mut pm_type_map: FxHashMap<+ api_enums::PaymentMethodType,+ FxHashMap<SessionRoutingConnectorKey, api::GetToken>,+ > = FxHashMap::default();let profile_id = session_input.payment_intent@@ -2674,7 +2685,7 @@ pub async fn perform_session_flow_routing(.entry(connector_data.payment_method_sub_type).or_default().insert(- connector_data.connector.connector_name.to_string(),+ connector_data.connector.merchant_connector_id.clone(),connector_data.connector.get_token.clone(),);}@@ -2719,7 +2730,10 @@ pub async fn perform_session_flow_routing(for selection in routable_connector_choice {let connector_name = selection.connector.to_string();- if let Some(get_token) = session_pm_input.allowed_connectors.get(&connector_name) {+ if let Some(get_token) = session_pm_input+ .allowed_connectors+ .get(&selection.merchant_connector_id)+ {let connector_data = api::ConnectorData::get_connector_by_name(&session_pm_input.state.clone().conf.connectors,&connector_name,