fix(router): avoid considering pre-routing results during perform_session_token_routing (#5076)

Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
Shankar Singh C
2024-06-21 22:39:22 +05:30
committed by GitHub
parent 6a07e10af3
commit a71fe033e7

View File

@ -3653,57 +3653,61 @@ pub async fn perform_session_token_routing<F>(
where where
F: Clone, F: Clone,
{ {
let routing_info: Option<storage::PaymentRoutingInfo> = payment_data // Commenting out this code as `list_payment_method_api` and `perform_session_token_routing`
.payment_attempt // will happen in parallel the behaviour of the session call differ based on filters in
.straight_through_algorithm // list_payment_method_api
.clone()
.map(|val| val.parse_value("PaymentRoutingInfo"))
.transpose()
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("invalid payment routing info format found in payment attempt")?;
if let Some(storage::PaymentRoutingInfo { // let routing_info: Option<storage::PaymentRoutingInfo> = payment_data
pre_routing_results: Some(pre_routing_results), // .payment_attempt
.. // .straight_through_algorithm
}) = routing_info // .clone()
{ // .map(|val| val.parse_value("PaymentRoutingInfo"))
let mut payment_methods: rustc_hash::FxHashMap< // .transpose()
(String, enums::PaymentMethodType), // .change_context(errors::ApiErrorResponse::InternalServerError)
api::SessionConnectorData, // .attach_printable("invalid payment routing info format found in payment attempt")?;
> = rustc_hash::FxHashMap::from_iter(connectors.iter().map(|c| {
(
(
c.connector.connector_name.to_string(),
c.payment_method_type,
),
c.clone(),
)
}));
let mut final_list: Vec<api::SessionConnectorData> = Vec::new(); // if let Some(storage::PaymentRoutingInfo {
for (routed_pm_type, pre_routing_choice) in pre_routing_results.into_iter() { // pre_routing_results: Some(pre_routing_results),
let routable_connector_list = match pre_routing_choice { // ..
storage::PreRoutingConnectorChoice::Single(routable_connector) => { // }) = routing_info
vec![routable_connector.clone()] // {
} // let mut payment_methods: rustc_hash::FxHashMap<
storage::PreRoutingConnectorChoice::Multiple(routable_connector_list) => { // (String, enums::PaymentMethodType),
routable_connector_list.clone() // api::SessionConnectorData,
} // > = rustc_hash::FxHashMap::from_iter(connectors.iter().map(|c| {
}; // (
for routable_connector in routable_connector_list { // (
if let Some(session_connector_data) = // c.connector.connector_name.to_string(),
payment_methods.remove(&(routable_connector.to_string(), routed_pm_type)) // c.payment_method_type,
{ // ),
final_list.push(session_connector_data); // c.clone(),
break; // )
} // }));
}
}
if !final_list.is_empty() { // let mut final_list: Vec<api::SessionConnectorData> = Vec::new();
return Ok(final_list); // for (routed_pm_type, pre_routing_choice) in pre_routing_results.into_iter() {
} // let routable_connector_list = match pre_routing_choice {
} // storage::PreRoutingConnectorChoice::Single(routable_connector) => {
// vec![routable_connector.clone()]
// }
// storage::PreRoutingConnectorChoice::Multiple(routable_connector_list) => {
// routable_connector_list.clone()
// }
// };
// for routable_connector in routable_connector_list {
// if let Some(session_connector_data) =
// payment_methods.remove(&(routable_connector.to_string(), routed_pm_type))
// {
// final_list.push(session_connector_data);
// break;
// }
// }
// }
// if !final_list.is_empty() {
// return Ok(final_list);
// }
// }
let routing_enabled_pms = HashSet::from([ let routing_enabled_pms = HashSet::from([
enums::PaymentMethodType::GooglePay, enums::PaymentMethodType::GooglePay,