mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-29 00:49:42 +08:00
refactor(routing): Remove backwards compatibility for the routing crate (#3015)
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com> Co-authored-by: Shanks <shashank.attarde@juspay.in>
This commit is contained in:
@ -9,17 +9,13 @@ license.workspace = true
|
||||
|
||||
[features]
|
||||
default = []
|
||||
business_profile_routing = []
|
||||
connector_choice_bcompat = []
|
||||
errors = ["dep:actix-web", "dep:reqwest"]
|
||||
backwards_compatibility = ["connector_choice_bcompat"]
|
||||
connector_choice_mca_id = ["euclid/connector_choice_mca_id"]
|
||||
dummy_connector = ["euclid/dummy_connector", "common_enums/dummy_connector"]
|
||||
detailed_errors = []
|
||||
payouts = []
|
||||
frm = []
|
||||
olap = []
|
||||
openapi = ["common_enums/openapi", "olap", "backwards_compatibility", "business_profile_routing", "connector_choice_mca_id", "recon", "dummy_connector", "olap"]
|
||||
openapi = ["common_enums/openapi", "olap", "recon", "dummy_connector", "olap"]
|
||||
recon = []
|
||||
v2 = []
|
||||
|
||||
|
||||
@ -3,10 +3,8 @@ use common_utils::events::{ApiEventMetric, ApiEventsType};
|
||||
use crate::routing::{
|
||||
LinkedRoutingConfigRetrieveResponse, MerchantRoutingAlgorithm, ProfileDefaultRoutingConfig,
|
||||
RoutingAlgorithmId, RoutingConfigRequest, RoutingDictionaryRecord, RoutingKind,
|
||||
RoutingPayloadWrapper,
|
||||
RoutingPayloadWrapper, RoutingRetrieveLinkQuery, RoutingRetrieveQuery,
|
||||
};
|
||||
#[cfg(feature = "business_profile_routing")]
|
||||
use crate::routing::{RoutingRetrieveLinkQuery, RoutingRetrieveQuery};
|
||||
|
||||
impl ApiEventMetric for RoutingKind {
|
||||
fn get_api_event_type(&self) -> Option<ApiEventsType> {
|
||||
@ -49,7 +47,6 @@ impl ApiEventMetric for ProfileDefaultRoutingConfig {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "business_profile_routing")]
|
||||
impl ApiEventMetric for RoutingRetrieveQuery {
|
||||
fn get_api_event_type(&self) -> Option<ApiEventsType> {
|
||||
Some(ApiEventsType::Routing)
|
||||
@ -62,7 +59,6 @@ impl ApiEventMetric for RoutingConfigRequest {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "business_profile_routing")]
|
||||
impl ApiEventMetric for RoutingRetrieveLinkQuery {
|
||||
fn get_api_event_type(&self) -> Option<ApiEventsType> {
|
||||
Some(ApiEventsType::Routing)
|
||||
|
||||
@ -45,7 +45,6 @@ pub struct ProfileDefaultRoutingConfig {
|
||||
pub connectors: Vec<RoutableConnectorChoice>,
|
||||
}
|
||||
|
||||
#[cfg(feature = "business_profile_routing")]
|
||||
#[derive(Debug, serde::Deserialize, serde::Serialize)]
|
||||
pub struct RoutingRetrieveQuery {
|
||||
pub limit: Option<u16>,
|
||||
@ -54,7 +53,6 @@ pub struct RoutingRetrieveQuery {
|
||||
pub profile_id: Option<String>,
|
||||
}
|
||||
|
||||
#[cfg(feature = "business_profile_routing")]
|
||||
#[derive(Debug, serde::Deserialize, serde::Serialize)]
|
||||
pub struct RoutingRetrieveLinkQuery {
|
||||
pub profile_id: Option<String>,
|
||||
@ -77,7 +75,6 @@ pub enum LinkedRoutingConfigRetrieveResponse {
|
||||
/// Routing Algorithm specific to merchants
|
||||
pub struct MerchantRoutingAlgorithm {
|
||||
pub id: String,
|
||||
#[cfg(feature = "business_profile_routing")]
|
||||
pub profile_id: String,
|
||||
pub name: String,
|
||||
pub description: String,
|
||||
@ -129,27 +126,17 @@ impl EuclidAnalysable for ConnectorSelection {
|
||||
.into_iter()
|
||||
.map(|connector_choice| {
|
||||
let connector_name = connector_choice.connector.to_string();
|
||||
#[cfg(not(feature = "connector_choice_mca_id"))]
|
||||
let sub_label = connector_choice.sub_label.clone();
|
||||
#[cfg(feature = "connector_choice_mca_id")]
|
||||
let mca_id = connector_choice.merchant_connector_id.clone();
|
||||
|
||||
(
|
||||
euclid::frontend::dir::DirValue::Connector(Box::new(connector_choice.into())),
|
||||
std::collections::HashMap::from_iter([(
|
||||
"CONNECTOR_SELECTION".to_string(),
|
||||
#[cfg(feature = "connector_choice_mca_id")]
|
||||
serde_json::json!({
|
||||
"rule_name": rule_name,
|
||||
"connector_name": connector_name,
|
||||
"mca_id": mca_id,
|
||||
}),
|
||||
#[cfg(not(feature = "connector_choice_mca_id"))]
|
||||
serde_json ::json!({
|
||||
"rule_name": rule_name,
|
||||
"connector_name": connector_name,
|
||||
"sub_label": sub_label,
|
||||
}),
|
||||
)]),
|
||||
)
|
||||
})
|
||||
@ -163,139 +150,86 @@ pub struct ConnectorVolumeSplit {
|
||||
pub split: u8,
|
||||
}
|
||||
|
||||
#[cfg(feature = "connector_choice_bcompat")]
|
||||
/// Routable Connector chosen for a payment
|
||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, ToSchema)]
|
||||
#[serde(from = "RoutableChoiceSerde", into = "RoutableChoiceSerde")]
|
||||
pub struct RoutableConnectorChoice {
|
||||
#[serde(skip)]
|
||||
pub choice_kind: RoutableChoiceKind,
|
||||
pub connector: RoutableConnectors,
|
||||
pub merchant_connector_id: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, serde::Deserialize, serde::Serialize, ToSchema)]
|
||||
pub enum RoutableChoiceKind {
|
||||
OnlyConnector,
|
||||
FullStruct,
|
||||
}
|
||||
|
||||
#[cfg(feature = "connector_choice_bcompat")]
|
||||
#[derive(Debug, serde::Deserialize, serde::Serialize)]
|
||||
#[serde(untagged)]
|
||||
pub enum RoutableChoiceSerde {
|
||||
OnlyConnector(Box<RoutableConnectors>),
|
||||
FullStruct {
|
||||
connector: RoutableConnectors,
|
||||
#[cfg(feature = "connector_choice_mca_id")]
|
||||
merchant_connector_id: Option<String>,
|
||||
#[cfg(not(feature = "connector_choice_mca_id"))]
|
||||
sub_label: Option<String>,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, ToSchema)]
|
||||
#[cfg_attr(
|
||||
feature = "connector_choice_bcompat",
|
||||
serde(from = "RoutableChoiceSerde"),
|
||||
serde(into = "RoutableChoiceSerde")
|
||||
)]
|
||||
#[cfg_attr(not(feature = "connector_choice_bcompat"), derive(PartialEq, Eq))]
|
||||
|
||||
/// Routable Connector chosen for a payment
|
||||
pub struct RoutableConnectorChoice {
|
||||
#[cfg(feature = "connector_choice_bcompat")]
|
||||
#[serde(skip)]
|
||||
pub choice_kind: RoutableChoiceKind,
|
||||
pub connector: RoutableConnectors,
|
||||
#[cfg(feature = "connector_choice_mca_id")]
|
||||
pub merchant_connector_id: Option<String>,
|
||||
#[cfg(not(feature = "connector_choice_mca_id"))]
|
||||
pub sub_label: Option<String>,
|
||||
}
|
||||
|
||||
impl std::fmt::Display for RoutableConnectorChoice {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
#[cfg(feature = "connector_choice_mca_id")]
|
||||
let base = self.connector.to_string();
|
||||
|
||||
#[cfg(not(feature = "connector_choice_mca_id"))]
|
||||
let base = {
|
||||
let mut sub_base = self.connector.to_string();
|
||||
if let Some(ref label) = self.sub_label {
|
||||
sub_base.push('_');
|
||||
sub_base.push_str(label);
|
||||
}
|
||||
|
||||
sub_base
|
||||
};
|
||||
|
||||
write!(f, "{}", base)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "connector_choice_bcompat")]
|
||||
impl PartialEq for RoutableConnectorChoice {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
#[cfg(not(feature = "connector_choice_mca_id"))]
|
||||
{
|
||||
self.connector.eq(&other.connector) && self.sub_label.eq(&other.sub_label)
|
||||
}
|
||||
|
||||
#[cfg(feature = "connector_choice_mca_id")]
|
||||
{
|
||||
self.connector.eq(&other.connector)
|
||||
&& self.merchant_connector_id.eq(&other.merchant_connector_id)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "connector_choice_bcompat")]
|
||||
impl Eq for RoutableConnectorChoice {}
|
||||
|
||||
#[cfg(feature = "connector_choice_bcompat")]
|
||||
impl From<RoutableChoiceSerde> for RoutableConnectorChoice {
|
||||
fn from(value: RoutableChoiceSerde) -> Self {
|
||||
match value {
|
||||
RoutableChoiceSerde::OnlyConnector(connector) => Self {
|
||||
choice_kind: RoutableChoiceKind::OnlyConnector,
|
||||
connector: *connector,
|
||||
#[cfg(feature = "connector_choice_mca_id")]
|
||||
merchant_connector_id: None,
|
||||
#[cfg(not(feature = "connector_choice_mca_id"))]
|
||||
sub_label: None,
|
||||
},
|
||||
|
||||
RoutableChoiceSerde::FullStruct {
|
||||
connector,
|
||||
#[cfg(feature = "connector_choice_mca_id")]
|
||||
merchant_connector_id,
|
||||
#[cfg(not(feature = "connector_choice_mca_id"))]
|
||||
sub_label,
|
||||
} => Self {
|
||||
choice_kind: RoutableChoiceKind::FullStruct,
|
||||
connector,
|
||||
#[cfg(feature = "connector_choice_mca_id")]
|
||||
merchant_connector_id,
|
||||
#[cfg(not(feature = "connector_choice_mca_id"))]
|
||||
sub_label,
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "connector_choice_bcompat")]
|
||||
impl From<RoutableConnectorChoice> for RoutableChoiceSerde {
|
||||
fn from(value: RoutableConnectorChoice) -> Self {
|
||||
match value.choice_kind {
|
||||
RoutableChoiceKind::OnlyConnector => Self::OnlyConnector(Box::new(value.connector)),
|
||||
RoutableChoiceKind::FullStruct => Self::FullStruct {
|
||||
connector: value.connector,
|
||||
#[cfg(feature = "connector_choice_mca_id")]
|
||||
merchant_connector_id: value.merchant_connector_id,
|
||||
#[cfg(not(feature = "connector_choice_mca_id"))]
|
||||
sub_label: value.sub_label,
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<RoutableConnectorChoice> for ast::ConnectorChoice {
|
||||
fn from(value: RoutableConnectorChoice) -> Self {
|
||||
Self {
|
||||
connector: value.connector,
|
||||
#[cfg(not(feature = "connector_choice_mca_id"))]
|
||||
sub_label: value.sub_label,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq for RoutableConnectorChoice {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.connector.eq(&other.connector)
|
||||
&& self.merchant_connector_id.eq(&other.merchant_connector_id)
|
||||
}
|
||||
}
|
||||
|
||||
impl Eq for RoutableConnectorChoice {}
|
||||
|
||||
impl From<RoutableChoiceSerde> for RoutableConnectorChoice {
|
||||
fn from(value: RoutableChoiceSerde) -> Self {
|
||||
match value {
|
||||
RoutableChoiceSerde::OnlyConnector(connector) => Self {
|
||||
choice_kind: RoutableChoiceKind::OnlyConnector,
|
||||
connector: *connector,
|
||||
merchant_connector_id: None,
|
||||
},
|
||||
|
||||
RoutableChoiceSerde::FullStruct {
|
||||
connector,
|
||||
merchant_connector_id,
|
||||
} => Self {
|
||||
choice_kind: RoutableChoiceKind::FullStruct,
|
||||
connector,
|
||||
merchant_connector_id,
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<RoutableConnectorChoice> for RoutableChoiceSerde {
|
||||
fn from(value: RoutableConnectorChoice) -> Self {
|
||||
match value.choice_kind {
|
||||
RoutableChoiceKind::OnlyConnector => Self::OnlyConnector(Box::new(value.connector)),
|
||||
RoutableChoiceKind::FullStruct => Self::FullStruct {
|
||||
connector: value.connector,
|
||||
merchant_connector_id: value.merchant_connector_id,
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -499,7 +433,7 @@ impl RoutingAlgorithmRef {
|
||||
|
||||
pub struct RoutingDictionaryRecord {
|
||||
pub id: String,
|
||||
#[cfg(feature = "business_profile_routing")]
|
||||
|
||||
pub profile_id: String,
|
||||
pub name: String,
|
||||
pub kind: RoutingAlgorithmKind,
|
||||
|
||||
Reference in New Issue
Block a user