Skip to content

Commit

Permalink
refactor(routing): Remove backwards compatibility for the routing cra…
Browse files Browse the repository at this point in the history
…te (#3015)

Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
Co-authored-by: Shanks <[email protected]>
  • Loading branch information
3 people authored Jul 18, 2024
1 parent a0c367e commit 78a7804
Show file tree
Hide file tree
Showing 122 changed files with 469 additions and 1,762 deletions.
6 changes: 1 addition & 5 deletions crates/api_models/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []

Expand Down
6 changes: 1 addition & 5 deletions crates/api_models/src/events/routing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
108 changes: 21 additions & 87 deletions crates/api_models/src/routing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
Expand All @@ -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>,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
}),
)]),
)
})
Expand All @@ -163,143 +150,90 @@ 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)
impl From<RoutableConnectorChoice> for ast::ConnectorChoice {
fn from(value: RoutableConnectorChoice) -> Self {
Self {
connector: value.connector,
}
}
}

#[cfg(feature = "connector_choice_mca_id")]
{
self.connector.eq(&other.connector)
&& self.merchant_connector_id.eq(&other.merchant_connector_id)
}
impl PartialEq for RoutableConnectorChoice {
fn eq(&self, other: &Self) -> bool {
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,
}
}
}

#[derive(Debug, Copy, Clone, serde::Serialize, serde::Deserialize, strum::Display, ToSchema)]
#[serde(rename_all = "snake_case")]
#[strum(serialize_all = "snake_case")]
Expand Down Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion crates/euclid/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ common_utils = { version = "0.1.0", path = "../common_utils"}
default = []
ast_parser = ["dep:nom"]
valued_jit = []
connector_choice_mca_id = []
dummy_connector = []
payouts = []

Expand Down
10 changes: 3 additions & 7 deletions crates/euclid/src/frontend/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ use crate::types::{DataType, Metadata};
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)]
pub struct ConnectorChoice {
pub connector: RoutableConnectors,
#[cfg(not(feature = "connector_choice_mca_id"))]
pub sub_label: Option<String>,
}

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, ToSchema)]
Expand Down Expand Up @@ -163,18 +161,16 @@ pub struct Program<O> {

#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
pub struct RoutableConnectorChoice {
#[cfg(feature = "connector_choice_bcompat")]
#[serde(skip)]
pub choice_kind: RoutableChoiceKind,
#[cfg(feature = "connector_choice_mca_id")]
pub connector: RoutableConnectors,
pub merchant_connector_id: Option<String>,
#[cfg(not(feature = "connector_choice_mca_id"))]
pub sub_label: Option<String>,
}

#[derive(Debug, Clone, Deserialize, Serialize, ToSchema)]
#[derive(Debug, Default, Clone, Deserialize, Serialize, ToSchema)]
pub enum RoutableChoiceKind {
OnlyConnector,
#[default]
FullStruct,
}

Expand Down
54 changes: 1 addition & 53 deletions crates/euclid/src/frontend/dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use strum::IntoEnumIterator;
use crate::{enums as euclid_enums, frontend::ast, types};

#[macro_export]
#[cfg(feature = "connector_choice_mca_id")]
macro_rules! dirval {
(Connector = $name:ident) => {
$crate::frontend::dir::DirValue::Connector(Box::new(
Expand Down Expand Up @@ -46,53 +45,6 @@ macro_rules! dirval {
}};
}

#[macro_export]
#[cfg(not(feature = "connector_choice_mca_id"))]
macro_rules! dirval {
(Connector = $name:ident) => {
$crate::frontend::dir::DirValue::Connector(Box::new(
$crate::frontend::ast::ConnectorChoice {
connector: $crate::enums::RoutableConnectors::$name,
sub_label: None,
},
))
};

(Connector = ($name:ident, $sub_label:literal)) => {
$crate::frontend::dir::DirValue::Connector(Box::new(
$crate::frontend::ast::ConnectorChoice {
connector: $crate::enums::RoutableConnectors::$name,
sub_label: Some($sub_label.to_string()),
},
))
};

($key:ident = $val:ident) => {{
pub use $crate::frontend::dir::enums::*;

$crate::frontend::dir::DirValue::$key($key::$val)
}};

($key:ident = $num:literal) => {{
$crate::frontend::dir::DirValue::$key($crate::types::NumValue {
number: common_utils::types::MinorUnit::new($num),
refinement: None,
})
}};

($key:ident s= $str:literal) => {{
$crate::frontend::dir::DirValue::$key($crate::types::StrValue {
value: $str.to_string(),
})
}};
($key:literal = $str:literal) => {{
$crate::frontend::dir::DirValue::MetaData($crate::types::MetadataValue {
key: $key.to_string(),
value: $str.to_string(),
})
}};
}

#[derive(Debug, Clone, Hash, PartialEq, Eq, serde::Serialize)]
pub struct DirKey {
pub kind: DirKeyKind,
Expand Down Expand Up @@ -482,11 +434,7 @@ impl DirKeyKind {
Self::Connector => Some(
common_enums::RoutableConnectors::iter()
.map(|connector| {
DirValue::Connector(Box::new(ast::ConnectorChoice {
connector,
#[cfg(not(feature = "connector_choice_mca_id"))]
sub_label: None,
}))
DirValue::Connector(Box::new(ast::ConnectorChoice { connector }))
})
.collect(),
),
Expand Down
6 changes: 2 additions & 4 deletions crates/euclid_wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ license.workspace = true
crate-type = ["cdylib"]

[features]
default = ["connector_choice_bcompat", "payouts", "connector_choice_mca_id"]
release = ["connector_choice_bcompat", "connector_choice_mca_id", "payouts"]
connector_choice_bcompat = ["api_models/connector_choice_bcompat"]
connector_choice_mca_id = ["api_models/connector_choice_mca_id", "euclid/connector_choice_mca_id", "kgraph_utils/connector_choice_mca_id"]
default = ["payouts"]
release = ["payouts"]
dummy_connector = ["kgraph_utils/dummy_connector", "connector_configs/dummy_connector"]
production = ["connector_configs/production"]
development = ["connector_configs/development"]
Expand Down
Loading

0 comments on commit 78a7804

Please sign in to comment.