mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-02 04:04:43 +08:00
feat(router): Add Smart Routing to route payments efficiently (#2665)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: shashank_attarde <shashank.attarde@juspay.in> Co-authored-by: Aprabhat19 <amishaprabhat@gmail.com> Co-authored-by: Amisha Prabhat <55580080+Aprabhat19@users.noreply.github.com>
This commit is contained in:
@ -9,7 +9,7 @@ use crate::{
|
||||
core::{api_locking::GetLockingInput, payment_methods::Oss, payments},
|
||||
routes,
|
||||
services::{api, authentication as auth},
|
||||
types::api::{self as api_types},
|
||||
types::api as api_types,
|
||||
};
|
||||
|
||||
#[instrument(skip_all, fields(flow = ?Flow::PaymentsCreate))]
|
||||
@ -50,6 +50,7 @@ pub async fn payment_intents_create(
|
||||
&req,
|
||||
create_payment_req,
|
||||
|state, auth, req| {
|
||||
let eligible_connectors = req.connector.clone();
|
||||
payments::payments_core::<api_types::Authorize, api_types::PaymentsResponse, _, _, _,Oss>(
|
||||
state,
|
||||
auth.merchant_account,
|
||||
@ -58,6 +59,7 @@ pub async fn payment_intents_create(
|
||||
req,
|
||||
api::AuthFlow::Merchant,
|
||||
payments::CallConnectorAction::Trigger,
|
||||
eligible_connectors,
|
||||
api_types::HeaderPayload::default(),
|
||||
)
|
||||
},
|
||||
@ -117,6 +119,7 @@ pub async fn payment_intents_retrieve(
|
||||
payload,
|
||||
auth_flow,
|
||||
payments::CallConnectorAction::Trigger,
|
||||
None,
|
||||
api_types::HeaderPayload::default(),
|
||||
)
|
||||
},
|
||||
@ -180,6 +183,7 @@ pub async fn payment_intents_retrieve_with_gateway_creds(
|
||||
req,
|
||||
api::AuthFlow::Merchant,
|
||||
payments::CallConnectorAction::Trigger,
|
||||
None,
|
||||
api_types::HeaderPayload::default(),
|
||||
)
|
||||
},
|
||||
@ -236,6 +240,7 @@ pub async fn payment_intents_update(
|
||||
&req,
|
||||
payload,
|
||||
|state, auth, req| {
|
||||
let eligible_connectors = req.connector.clone();
|
||||
payments::payments_core::<api_types::Authorize, api_types::PaymentsResponse, _, _, _,Oss>(
|
||||
state,
|
||||
auth.merchant_account,
|
||||
@ -244,6 +249,7 @@ pub async fn payment_intents_update(
|
||||
req,
|
||||
auth_flow,
|
||||
payments::CallConnectorAction::Trigger,
|
||||
eligible_connectors,
|
||||
api_types::HeaderPayload::default(),
|
||||
)
|
||||
},
|
||||
@ -302,6 +308,7 @@ pub async fn payment_intents_confirm(
|
||||
&req,
|
||||
payload,
|
||||
|state, auth, req| {
|
||||
let eligible_connectors = req.connector.clone();
|
||||
payments::payments_core::<api_types::Authorize, api_types::PaymentsResponse, _, _, _,Oss>(
|
||||
state,
|
||||
auth.merchant_account,
|
||||
@ -310,6 +317,7 @@ pub async fn payment_intents_confirm(
|
||||
req,
|
||||
auth_flow,
|
||||
payments::CallConnectorAction::Trigger,
|
||||
eligible_connectors,
|
||||
api_types::HeaderPayload::default(),
|
||||
)
|
||||
},
|
||||
@ -366,6 +374,7 @@ pub async fn payment_intents_capture(
|
||||
payload,
|
||||
api::AuthFlow::Merchant,
|
||||
payments::CallConnectorAction::Trigger,
|
||||
None,
|
||||
api_types::HeaderPayload::default(),
|
||||
)
|
||||
},
|
||||
@ -426,6 +435,7 @@ pub async fn payment_intents_cancel(
|
||||
req,
|
||||
auth_flow,
|
||||
payments::CallConnectorAction::Trigger,
|
||||
None,
|
||||
api_types::HeaderPayload::default(),
|
||||
)
|
||||
},
|
||||
|
||||
@ -282,9 +282,17 @@ impl TryFrom<StripePaymentIntentRequest> for payments::PaymentsRequest {
|
||||
|
||||
let routing = routable_connector
|
||||
.map(|connector| {
|
||||
crate::types::api::RoutingAlgorithm::Single(
|
||||
api_models::admin::RoutableConnectorChoice::ConnectorName(connector),
|
||||
)
|
||||
api_models::routing::RoutingAlgorithm::Single(Box::new(
|
||||
api_models::routing::RoutableConnectorChoice {
|
||||
#[cfg(feature = "backwards_compatibility")]
|
||||
choice_kind: api_models::routing::RoutableChoiceKind::FullStruct,
|
||||
connector,
|
||||
#[cfg(feature = "connector_choice_mca_id")]
|
||||
merchant_connector_id: None,
|
||||
#[cfg(not(feature = "connector_choice_mca_id"))]
|
||||
sub_label: None,
|
||||
},
|
||||
))
|
||||
})
|
||||
.map(|r| {
|
||||
serde_json::to_value(r)
|
||||
|
||||
@ -69,6 +69,7 @@ pub async fn setup_intents_create(
|
||||
req,
|
||||
api::AuthFlow::Merchant,
|
||||
payments::CallConnectorAction::Trigger,
|
||||
None,
|
||||
api_types::HeaderPayload::default(),
|
||||
)
|
||||
},
|
||||
@ -128,6 +129,7 @@ pub async fn setup_intents_retrieve(
|
||||
payload,
|
||||
auth_flow,
|
||||
payments::CallConnectorAction::Trigger,
|
||||
None,
|
||||
api_types::HeaderPayload::default(),
|
||||
)
|
||||
},
|
||||
@ -200,6 +202,7 @@ pub async fn setup_intents_update(
|
||||
req,
|
||||
auth_flow,
|
||||
payments::CallConnectorAction::Trigger,
|
||||
None,
|
||||
api_types::HeaderPayload::default(),
|
||||
)
|
||||
},
|
||||
@ -273,6 +276,7 @@ pub async fn setup_intents_confirm(
|
||||
req,
|
||||
auth_flow,
|
||||
payments::CallConnectorAction::Trigger,
|
||||
None,
|
||||
api_types::HeaderPayload::default(),
|
||||
)
|
||||
},
|
||||
|
||||
@ -185,9 +185,17 @@ impl TryFrom<StripeSetupIntentRequest> for payments::PaymentsRequest {
|
||||
|
||||
let routing = routable_connector
|
||||
.map(|connector| {
|
||||
crate::types::api::RoutingAlgorithm::Single(
|
||||
api_models::admin::RoutableConnectorChoice::ConnectorName(connector),
|
||||
)
|
||||
api_models::routing::RoutingAlgorithm::Single(Box::new(
|
||||
api_models::routing::RoutableConnectorChoice {
|
||||
#[cfg(feature = "backwards_compatibility")]
|
||||
choice_kind: api_models::routing::RoutableChoiceKind::FullStruct,
|
||||
connector,
|
||||
#[cfg(feature = "connector_choice_mca_id")]
|
||||
merchant_connector_id: None,
|
||||
#[cfg(not(feature = "connector_choice_mca_id"))]
|
||||
sub_label: None,
|
||||
},
|
||||
))
|
||||
})
|
||||
.map(|r| {
|
||||
serde_json::to_value(r)
|
||||
|
||||
Reference in New Issue
Block a user