Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(routing): Remove backwards compatibility for the routing crate #3015

Merged
merged 36 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
33987a4
backwards compat for profile_specific routing removed
Aprabhat19 Nov 29, 2023
8a00d86
connector_choice_mca_id
Aprabhat19 Nov 29, 2023
63987d3
remove business_profile_routing as backwards compat
Aprabhat19 Nov 29, 2023
2c5d45e
fix clippy lints
Aprabhat19 Nov 29, 2023
bd25fa2
removed the backwards compat for connector_choice_kind feature
Aprabhat19 Nov 29, 2023
7765462
Merge branch 'main' into rmove-backwards-compat
Aprabhat19 Nov 29, 2023
3c02ce4
chore: run formatter
hyperswitch-bot[bot] Nov 29, 2023
761edc6
Merge branch 'main' into rmove-backwards-compat
Aprabhat19 Nov 30, 2023
a764c88
Merge branch 'main' into rmove-backwards-compat
Aprabhat19 Dec 4, 2023
95868bb
Merge branch 'main' of github.com:juspay/hyperswitch into rmove-backw…
Aprabhat19 Dec 5, 2023
1a7be72
resolve failing postman checks
Aprabhat19 Dec 5, 2023
8788f21
Merge branch 'rmove-backwards-compat' of https://github.com/juspay/hy…
Aprabhat19 Dec 5, 2023
d9c6368
Merge branch 'main' into rmove-backwards-compat
Aprabhat19 Dec 5, 2023
47730b3
Merge branch 'main' of github.com:juspay/hyperswitch into rmove-backw…
Aprabhat19 Dec 5, 2023
25174d5
Merge branch 'rmove-backwards-compat' of github.com:juspay/hyperswitc…
Aprabhat19 Dec 5, 2023
fb15e1a
Merge branch 'main' of github.com:juspay/hyperswitch into rmove-backw…
Aprabhat19 Dec 5, 2023
3ef7fed
Merge branch 'main' into rmove-backwards-compat
Aprabhat19 Dec 5, 2023
e68fcc8
Merge branch 'rmove-backwards-compat' of github.com:juspay/hyperswitc…
Aprabhat19 Dec 5, 2023
2608388
resolved conflicts
Aprabhat19 Dec 6, 2023
71ff4a0
conflicts resolved
Aprabhat19 Dec 6, 2023
cb0e899
resolve conflucts
Aprabhat19 Dec 6, 2023
4d9841b
fmt re run
Aprabhat19 Dec 6, 2023
9e877fe
cargo toml changes
Aprabhat19 Dec 6, 2023
cdcd789
Merge branch 'main' into rmove-backwards-compat
Aprabhat19 Dec 6, 2023
1386858
resolved conflicts
Aprabhat19 Dec 14, 2023
142a487
remove backwards compatibility
Aprabhat19 Dec 14, 2023
2a9d86a
resolved conflicts
Aprabhat19 Jul 16, 2024
f0537bc
Merge branch 'main' of https://github.com/juspay/hyperswitch into rmo…
Aprabhat19 Jul 16, 2024
2325201
chore: run formatter
hyperswitch-bot[bot] Jul 16, 2024
0770435
Merge branch 'rmove-backwards-compat' of https://github.com/juspay/hy…
Aprabhat19 Jul 16, 2024
e15f4c8
fix postman collection
Aprabhat19 Jul 16, 2024
7d54b81
Merge branch 'main' into rmove-backwards-compat
Aprabhat19 Jul 17, 2024
0e342c3
addressed comments
Aprabhat19 Jul 17, 2024
b7b4d7b
Merge branch 'rmove-backwards-compat' of https://github.com/juspay/hy…
Aprabhat19 Jul 17, 2024
f5cb11a
remove unnecessary comma
Aprabhat19 Jul 17, 2024
56a40b5
Update crates/router/src/core/payments.rs
Aprabhat19 Jul 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -474,11 +426,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", ]
SanchithHegde marked this conversation as resolved.
Show resolved Hide resolved
release = ["payouts"]
dummy_connector = ["kgraph_utils/dummy_connector", "connector_configs/dummy_connector"]
production = ["connector_configs/production"]
development = ["connector_configs/development"]
Expand Down
Loading
Loading