mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-29 17:19:15 +08:00
feat(routing): add domain type for Routing id (#5733)
Co-authored-by: Sanchith Hegde <sanchith.hegde@juspay.in> Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
@ -89,7 +89,8 @@ pub enum LinkedRoutingConfigRetrieveResponse {
|
|||||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, ToSchema)]
|
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, ToSchema)]
|
||||||
/// Routing Algorithm specific to merchants
|
/// Routing Algorithm specific to merchants
|
||||||
pub struct MerchantRoutingAlgorithm {
|
pub struct MerchantRoutingAlgorithm {
|
||||||
pub id: String,
|
#[schema(value_type = String)]
|
||||||
|
pub id: common_utils::id_type::RoutingId,
|
||||||
#[schema(value_type = String)]
|
#[schema(value_type = String)]
|
||||||
pub profile_id: common_utils::id_type::ProfileId,
|
pub profile_id: common_utils::id_type::ProfileId,
|
||||||
pub name: String,
|
pub name: String,
|
||||||
@ -422,14 +423,14 @@ impl RoutingAlgorithm {
|
|||||||
|
|
||||||
#[derive(Debug, Default, Clone, serde::Serialize, serde::Deserialize)]
|
#[derive(Debug, Default, Clone, serde::Serialize, serde::Deserialize)]
|
||||||
pub struct RoutingAlgorithmRef {
|
pub struct RoutingAlgorithmRef {
|
||||||
pub algorithm_id: Option<String>,
|
pub algorithm_id: Option<common_utils::id_type::RoutingId>,
|
||||||
pub timestamp: i64,
|
pub timestamp: i64,
|
||||||
pub config_algo_id: Option<String>,
|
pub config_algo_id: Option<String>,
|
||||||
pub surcharge_config_algo_id: Option<String>,
|
pub surcharge_config_algo_id: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RoutingAlgorithmRef {
|
impl RoutingAlgorithmRef {
|
||||||
pub fn update_algorithm_id(&mut self, new_id: String) {
|
pub fn update_algorithm_id(&mut self, new_id: common_utils::id_type::RoutingId) {
|
||||||
self.algorithm_id = Some(new_id);
|
self.algorithm_id = Some(new_id);
|
||||||
self.timestamp = common_utils::date_time::now_unix_timestamp();
|
self.timestamp = common_utils::date_time::now_unix_timestamp();
|
||||||
}
|
}
|
||||||
@ -456,7 +457,8 @@ impl RoutingAlgorithmRef {
|
|||||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, ToSchema)]
|
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, ToSchema)]
|
||||||
|
|
||||||
pub struct RoutingDictionaryRecord {
|
pub struct RoutingDictionaryRecord {
|
||||||
pub id: String,
|
#[schema(value_type = String)]
|
||||||
|
pub id: common_utils::id_type::RoutingId,
|
||||||
#[schema(value_type = String)]
|
#[schema(value_type = String)]
|
||||||
pub profile_id: common_utils::id_type::ProfileId,
|
pub profile_id: common_utils::id_type::ProfileId,
|
||||||
pub name: String,
|
pub name: String,
|
||||||
@ -484,7 +486,8 @@ pub enum RoutingKind {
|
|||||||
|
|
||||||
#[derive(serde::Serialize, serde::Deserialize, Debug, Clone, ToSchema)]
|
#[derive(serde::Serialize, serde::Deserialize, Debug, Clone, ToSchema)]
|
||||||
pub struct RoutingAlgorithmId {
|
pub struct RoutingAlgorithmId {
|
||||||
pub routing_algorithm_id: String,
|
#[schema(value_type = String)]
|
||||||
|
pub routing_algorithm_id: common_utils::id_type::RoutingId,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
||||||
|
|||||||
@ -8,6 +8,7 @@ mod merchant;
|
|||||||
mod merchant_connector_account;
|
mod merchant_connector_account;
|
||||||
mod organization;
|
mod organization;
|
||||||
mod profile;
|
mod profile;
|
||||||
|
mod routing;
|
||||||
|
|
||||||
mod global_id;
|
mod global_id;
|
||||||
|
|
||||||
@ -23,6 +24,7 @@ pub use merchant::MerchantId;
|
|||||||
pub use merchant_connector_account::MerchantConnectorAccountId;
|
pub use merchant_connector_account::MerchantConnectorAccountId;
|
||||||
pub use organization::OrganizationId;
|
pub use organization::OrganizationId;
|
||||||
pub use profile::ProfileId;
|
pub use profile::ProfileId;
|
||||||
|
pub use routing::RoutingId;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
|
|||||||
21
crates/common_utils/src/id_type/routing.rs
Normal file
21
crates/common_utils/src/id_type/routing.rs
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
crate::id_type!(
|
||||||
|
RoutingId,
|
||||||
|
" A type for routing_id that can be used for routing ids"
|
||||||
|
);
|
||||||
|
|
||||||
|
crate::impl_id_type_methods!(RoutingId, "routing_id");
|
||||||
|
|
||||||
|
// This is to display the `RoutingId` as RoutingId(abcd)
|
||||||
|
crate::impl_debug_id_type!(RoutingId);
|
||||||
|
crate::impl_try_from_cow_str_id_type!(RoutingId, "routing_id");
|
||||||
|
|
||||||
|
crate::impl_generate_id_id_type!(RoutingId, "routing");
|
||||||
|
crate::impl_serializable_secret_id_type!(RoutingId);
|
||||||
|
crate::impl_queryable_id_type!(RoutingId);
|
||||||
|
crate::impl_to_sql_from_sql_id_type!(RoutingId);
|
||||||
|
|
||||||
|
impl crate::events::ApiEventMetric for RoutingId {
|
||||||
|
fn get_api_event_type(&self) -> Option<crate::events::ApiEventsType> {
|
||||||
|
Some(crate::events::ApiEventsType::Routing)
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -233,6 +233,12 @@ pub fn generate_profile_id_of_default_length() -> id_type::ProfileId {
|
|||||||
id_type::ProfileId::generate()
|
id_type::ProfileId::generate()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Generate a routing id with default length, with prefix as `routing`
|
||||||
|
pub fn generate_routing_id_of_default_length() -> id_type::RoutingId {
|
||||||
|
use id_type::GenerateId;
|
||||||
|
|
||||||
|
id_type::RoutingId::generate()
|
||||||
|
}
|
||||||
/// Generate a merchant_connector_account id with default length, with prefix as `mca`
|
/// Generate a merchant_connector_account id with default length, with prefix as `mca`
|
||||||
pub fn generate_merchant_connector_account_id_of_default_length(
|
pub fn generate_merchant_connector_account_id_of_default_length(
|
||||||
) -> id_type::MerchantConnectorAccountId {
|
) -> id_type::MerchantConnectorAccountId {
|
||||||
|
|||||||
@ -269,11 +269,11 @@ pub struct BusinessProfile {
|
|||||||
pub outgoing_webhook_custom_http_headers: Option<Encryption>,
|
pub outgoing_webhook_custom_http_headers: Option<Encryption>,
|
||||||
pub always_collect_billing_details_from_wallet_connector: Option<bool>,
|
pub always_collect_billing_details_from_wallet_connector: Option<bool>,
|
||||||
pub always_collect_shipping_details_from_wallet_connector: Option<bool>,
|
pub always_collect_shipping_details_from_wallet_connector: Option<bool>,
|
||||||
pub routing_algorithm_id: Option<String>,
|
pub routing_algorithm_id: Option<common_utils::id_type::RoutingId>,
|
||||||
pub order_fulfillment_time: Option<i64>,
|
pub order_fulfillment_time: Option<i64>,
|
||||||
pub order_fulfillment_time_origin: Option<common_enums::OrderFulfillmentTimeOrigin>,
|
pub order_fulfillment_time_origin: Option<common_enums::OrderFulfillmentTimeOrigin>,
|
||||||
pub frm_routing_algorithm_id: Option<String>,
|
pub frm_routing_algorithm_id: Option<String>,
|
||||||
pub payout_routing_algorithm_id: Option<String>,
|
pub payout_routing_algorithm_id: Option<common_utils::id_type::RoutingId>,
|
||||||
pub default_fallback_routing: Option<pii::SecretSerdeValue>,
|
pub default_fallback_routing: Option<pii::SecretSerdeValue>,
|
||||||
pub tax_connector_id: Option<String>,
|
pub tax_connector_id: Option<String>,
|
||||||
pub is_tax_connector_enabled: Option<bool>,
|
pub is_tax_connector_enabled: Option<bool>,
|
||||||
@ -310,11 +310,11 @@ pub struct BusinessProfileNew {
|
|||||||
pub outgoing_webhook_custom_http_headers: Option<Encryption>,
|
pub outgoing_webhook_custom_http_headers: Option<Encryption>,
|
||||||
pub always_collect_billing_details_from_wallet_connector: Option<bool>,
|
pub always_collect_billing_details_from_wallet_connector: Option<bool>,
|
||||||
pub always_collect_shipping_details_from_wallet_connector: Option<bool>,
|
pub always_collect_shipping_details_from_wallet_connector: Option<bool>,
|
||||||
pub routing_algorithm_id: Option<String>,
|
pub routing_algorithm_id: Option<common_utils::id_type::RoutingId>,
|
||||||
pub order_fulfillment_time: Option<i64>,
|
pub order_fulfillment_time: Option<i64>,
|
||||||
pub order_fulfillment_time_origin: Option<common_enums::OrderFulfillmentTimeOrigin>,
|
pub order_fulfillment_time_origin: Option<common_enums::OrderFulfillmentTimeOrigin>,
|
||||||
pub frm_routing_algorithm_id: Option<String>,
|
pub frm_routing_algorithm_id: Option<String>,
|
||||||
pub payout_routing_algorithm_id: Option<String>,
|
pub payout_routing_algorithm_id: Option<common_utils::id_type::RoutingId>,
|
||||||
pub default_fallback_routing: Option<pii::SecretSerdeValue>,
|
pub default_fallback_routing: Option<pii::SecretSerdeValue>,
|
||||||
pub tax_connector_id: Option<String>,
|
pub tax_connector_id: Option<String>,
|
||||||
pub is_tax_connector_enabled: Option<bool>,
|
pub is_tax_connector_enabled: Option<bool>,
|
||||||
@ -348,11 +348,11 @@ pub struct BusinessProfileUpdateInternal {
|
|||||||
pub outgoing_webhook_custom_http_headers: Option<Encryption>,
|
pub outgoing_webhook_custom_http_headers: Option<Encryption>,
|
||||||
pub always_collect_billing_details_from_wallet_connector: Option<bool>,
|
pub always_collect_billing_details_from_wallet_connector: Option<bool>,
|
||||||
pub always_collect_shipping_details_from_wallet_connector: Option<bool>,
|
pub always_collect_shipping_details_from_wallet_connector: Option<bool>,
|
||||||
pub routing_algorithm_id: Option<String>,
|
pub routing_algorithm_id: Option<common_utils::id_type::RoutingId>,
|
||||||
pub order_fulfillment_time: Option<i64>,
|
pub order_fulfillment_time: Option<i64>,
|
||||||
pub order_fulfillment_time_origin: Option<common_enums::OrderFulfillmentTimeOrigin>,
|
pub order_fulfillment_time_origin: Option<common_enums::OrderFulfillmentTimeOrigin>,
|
||||||
pub frm_routing_algorithm_id: Option<String>,
|
pub frm_routing_algorithm_id: Option<String>,
|
||||||
pub payout_routing_algorithm_id: Option<String>,
|
pub payout_routing_algorithm_id: Option<common_utils::id_type::RoutingId>,
|
||||||
pub default_fallback_routing: Option<pii::SecretSerdeValue>,
|
pub default_fallback_routing: Option<pii::SecretSerdeValue>,
|
||||||
pub tax_connector_id: Option<String>,
|
pub tax_connector_id: Option<String>,
|
||||||
pub is_tax_connector_enabled: Option<bool>,
|
pub is_tax_connector_enabled: Option<bool>,
|
||||||
|
|||||||
@ -19,7 +19,7 @@ impl RoutingAlgorithm {
|
|||||||
|
|
||||||
pub async fn find_by_algorithm_id_merchant_id(
|
pub async fn find_by_algorithm_id_merchant_id(
|
||||||
conn: &PgPooledConn,
|
conn: &PgPooledConn,
|
||||||
algorithm_id: &str,
|
algorithm_id: &common_utils::id_type::RoutingId,
|
||||||
merchant_id: &common_utils::id_type::MerchantId,
|
merchant_id: &common_utils::id_type::MerchantId,
|
||||||
) -> StorageResult<Self> {
|
) -> StorageResult<Self> {
|
||||||
generics::generic_find_one::<<Self as HasTable>::Table, _, _>(
|
generics::generic_find_one::<<Self as HasTable>::Table, _, _>(
|
||||||
@ -33,7 +33,7 @@ impl RoutingAlgorithm {
|
|||||||
|
|
||||||
pub async fn find_by_algorithm_id_profile_id(
|
pub async fn find_by_algorithm_id_profile_id(
|
||||||
conn: &PgPooledConn,
|
conn: &PgPooledConn,
|
||||||
algorithm_id: &str,
|
algorithm_id: &common_utils::id_type::RoutingId,
|
||||||
profile_id: &common_utils::id_type::ProfileId,
|
profile_id: &common_utils::id_type::ProfileId,
|
||||||
) -> StorageResult<Self> {
|
) -> StorageResult<Self> {
|
||||||
generics::generic_find_one::<<Self as HasTable>::Table, _, _>(
|
generics::generic_find_one::<<Self as HasTable>::Table, _, _>(
|
||||||
@ -47,7 +47,7 @@ impl RoutingAlgorithm {
|
|||||||
|
|
||||||
pub async fn find_metadata_by_algorithm_id_profile_id(
|
pub async fn find_metadata_by_algorithm_id_profile_id(
|
||||||
conn: &PgPooledConn,
|
conn: &PgPooledConn,
|
||||||
algorithm_id: &str,
|
algorithm_id: &common_utils::id_type::RoutingId,
|
||||||
profile_id: &common_utils::id_type::ProfileId,
|
profile_id: &common_utils::id_type::ProfileId,
|
||||||
) -> StorageResult<RoutingProfileMetadata> {
|
) -> StorageResult<RoutingProfileMetadata> {
|
||||||
Self::table()
|
Self::table()
|
||||||
@ -69,7 +69,7 @@ impl RoutingAlgorithm {
|
|||||||
.limit(1)
|
.limit(1)
|
||||||
.load_async::<(
|
.load_async::<(
|
||||||
common_utils::id_type::ProfileId,
|
common_utils::id_type::ProfileId,
|
||||||
String,
|
common_utils::id_type::RoutingId,
|
||||||
String,
|
String,
|
||||||
Option<String>,
|
Option<String>,
|
||||||
enums::RoutingAlgorithmKind,
|
enums::RoutingAlgorithmKind,
|
||||||
@ -128,7 +128,7 @@ impl RoutingAlgorithm {
|
|||||||
.limit(limit)
|
.limit(limit)
|
||||||
.offset(offset)
|
.offset(offset)
|
||||||
.load_async::<(
|
.load_async::<(
|
||||||
String,
|
common_utils::id_type::RoutingId,
|
||||||
common_utils::id_type::ProfileId,
|
common_utils::id_type::ProfileId,
|
||||||
String,
|
String,
|
||||||
Option<String>,
|
Option<String>,
|
||||||
@ -189,7 +189,7 @@ impl RoutingAlgorithm {
|
|||||||
.order(dsl::modified_at.desc())
|
.order(dsl::modified_at.desc())
|
||||||
.load_async::<(
|
.load_async::<(
|
||||||
common_utils::id_type::ProfileId,
|
common_utils::id_type::ProfileId,
|
||||||
String,
|
common_utils::id_type::RoutingId,
|
||||||
String,
|
String,
|
||||||
Option<String>,
|
Option<String>,
|
||||||
enums::RoutingAlgorithmKind,
|
enums::RoutingAlgorithmKind,
|
||||||
@ -251,7 +251,7 @@ impl RoutingAlgorithm {
|
|||||||
.order(dsl::modified_at.desc())
|
.order(dsl::modified_at.desc())
|
||||||
.load_async::<(
|
.load_async::<(
|
||||||
common_utils::id_type::ProfileId,
|
common_utils::id_type::ProfileId,
|
||||||
String,
|
common_utils::id_type::RoutingId,
|
||||||
String,
|
String,
|
||||||
Option<String>,
|
Option<String>,
|
||||||
enums::RoutingAlgorithmKind,
|
enums::RoutingAlgorithmKind,
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
use common_utils::id_type;
|
||||||
use diesel::{Identifiable, Insertable, Queryable, Selectable};
|
use diesel::{Identifiable, Insertable, Queryable, Selectable};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
@ -6,9 +7,9 @@ use crate::{enums, schema::routing_algorithm};
|
|||||||
#[derive(Clone, Debug, Identifiable, Insertable, Queryable, Selectable, Serialize, Deserialize)]
|
#[derive(Clone, Debug, Identifiable, Insertable, Queryable, Selectable, Serialize, Deserialize)]
|
||||||
#[diesel(table_name = routing_algorithm, primary_key(algorithm_id), check_for_backend(diesel::pg::Pg))]
|
#[diesel(table_name = routing_algorithm, primary_key(algorithm_id), check_for_backend(diesel::pg::Pg))]
|
||||||
pub struct RoutingAlgorithm {
|
pub struct RoutingAlgorithm {
|
||||||
pub algorithm_id: String,
|
pub algorithm_id: id_type::RoutingId,
|
||||||
pub profile_id: common_utils::id_type::ProfileId,
|
pub profile_id: id_type::ProfileId,
|
||||||
pub merchant_id: common_utils::id_type::MerchantId,
|
pub merchant_id: id_type::MerchantId,
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub description: Option<String>,
|
pub description: Option<String>,
|
||||||
pub kind: enums::RoutingAlgorithmKind,
|
pub kind: enums::RoutingAlgorithmKind,
|
||||||
@ -19,7 +20,7 @@ pub struct RoutingAlgorithm {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub struct RoutingAlgorithmMetadata {
|
pub struct RoutingAlgorithmMetadata {
|
||||||
pub algorithm_id: String,
|
pub algorithm_id: id_type::RoutingId,
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub description: Option<String>,
|
pub description: Option<String>,
|
||||||
pub kind: enums::RoutingAlgorithmKind,
|
pub kind: enums::RoutingAlgorithmKind,
|
||||||
@ -29,8 +30,8 @@ pub struct RoutingAlgorithmMetadata {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub struct RoutingProfileMetadata {
|
pub struct RoutingProfileMetadata {
|
||||||
pub profile_id: common_utils::id_type::ProfileId,
|
pub profile_id: id_type::ProfileId,
|
||||||
pub algorithm_id: String,
|
pub algorithm_id: id_type::RoutingId,
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub description: Option<String>,
|
pub description: Option<String>,
|
||||||
pub kind: enums::RoutingAlgorithmKind,
|
pub kind: enums::RoutingAlgorithmKind,
|
||||||
|
|||||||
@ -479,11 +479,11 @@ pub struct BusinessProfile {
|
|||||||
pub outgoing_webhook_custom_http_headers: OptionalEncryptableValue,
|
pub outgoing_webhook_custom_http_headers: OptionalEncryptableValue,
|
||||||
pub always_collect_billing_details_from_wallet_connector: Option<bool>,
|
pub always_collect_billing_details_from_wallet_connector: Option<bool>,
|
||||||
pub always_collect_shipping_details_from_wallet_connector: Option<bool>,
|
pub always_collect_shipping_details_from_wallet_connector: Option<bool>,
|
||||||
pub routing_algorithm_id: Option<String>,
|
pub routing_algorithm_id: Option<common_utils::id_type::RoutingId>,
|
||||||
pub order_fulfillment_time: Option<i64>,
|
pub order_fulfillment_time: Option<i64>,
|
||||||
pub order_fulfillment_time_origin: Option<common_enums::OrderFulfillmentTimeOrigin>,
|
pub order_fulfillment_time_origin: Option<common_enums::OrderFulfillmentTimeOrigin>,
|
||||||
pub frm_routing_algorithm_id: Option<String>,
|
pub frm_routing_algorithm_id: Option<String>,
|
||||||
pub payout_routing_algorithm_id: Option<String>,
|
pub payout_routing_algorithm_id: Option<common_utils::id_type::RoutingId>,
|
||||||
pub default_fallback_routing: Option<pii::SecretSerdeValue>,
|
pub default_fallback_routing: Option<pii::SecretSerdeValue>,
|
||||||
pub tax_connector_id: Option<String>,
|
pub tax_connector_id: Option<String>,
|
||||||
pub is_tax_connector_enabled: bool,
|
pub is_tax_connector_enabled: bool,
|
||||||
@ -536,8 +536,8 @@ pub struct BusinessProfileGeneralUpdate {
|
|||||||
pub enum BusinessProfileUpdate {
|
pub enum BusinessProfileUpdate {
|
||||||
Update(Box<BusinessProfileGeneralUpdate>),
|
Update(Box<BusinessProfileGeneralUpdate>),
|
||||||
RoutingAlgorithmUpdate {
|
RoutingAlgorithmUpdate {
|
||||||
routing_algorithm_id: Option<String>,
|
routing_algorithm_id: Option<common_utils::id_type::RoutingId>,
|
||||||
payout_routing_algorithm_id: Option<String>,
|
payout_routing_algorithm_id: Option<common_utils::id_type::RoutingId>,
|
||||||
},
|
},
|
||||||
DefaultRoutingFallbackUpdate {
|
DefaultRoutingFallbackUpdate {
|
||||||
default_fallback_routing: Option<pii::SecretSerdeValue>,
|
default_fallback_routing: Option<pii::SecretSerdeValue>,
|
||||||
|
|||||||
@ -4073,7 +4073,7 @@ impl BusinessProfileWrapper {
|
|||||||
db: &dyn StorageInterface,
|
db: &dyn StorageInterface,
|
||||||
key_manager_state: &KeyManagerState,
|
key_manager_state: &KeyManagerState,
|
||||||
merchant_key_store: &domain::MerchantKeyStore,
|
merchant_key_store: &domain::MerchantKeyStore,
|
||||||
algorithm_id: String,
|
algorithm_id: common_utils::id_type::RoutingId,
|
||||||
transaction_type: &storage::enums::TransactionType,
|
transaction_type: &storage::enums::TransactionType,
|
||||||
) -> RouterResult<()> {
|
) -> RouterResult<()> {
|
||||||
let routing_cache_key = self.clone().get_routing_config_cache_key();
|
let routing_cache_key = self.clone().get_routing_config_cache_key();
|
||||||
@ -4114,7 +4114,7 @@ impl BusinessProfileWrapper {
|
|||||||
pub fn get_routing_algorithm_id<'a, F>(
|
pub fn get_routing_algorithm_id<'a, F>(
|
||||||
&'a self,
|
&'a self,
|
||||||
transaction_data: &'a routing::TransactionData<'_, F>,
|
transaction_data: &'a routing::TransactionData<'_, F>,
|
||||||
) -> Option<String>
|
) -> Option<id_type::RoutingId>
|
||||||
where
|
where
|
||||||
F: Send + Clone,
|
F: Send + Clone,
|
||||||
{
|
{
|
||||||
|
|||||||
@ -114,7 +114,7 @@ impl Default for MerchantAccountRoutingAlgorithm {
|
|||||||
#[derive(Debug, serde::Serialize, serde::Deserialize)]
|
#[derive(Debug, serde::Serialize, serde::Deserialize)]
|
||||||
#[serde(untagged)]
|
#[serde(untagged)]
|
||||||
enum MerchantAccountRoutingAlgorithm {
|
enum MerchantAccountRoutingAlgorithm {
|
||||||
V1(Option<String>),
|
V1(Option<common_utils::id_type::RoutingId>),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "payouts")]
|
#[cfg(feature = "payouts")]
|
||||||
@ -289,7 +289,7 @@ where
|
|||||||
pub async fn perform_static_routing_v1<F: Clone>(
|
pub async fn perform_static_routing_v1<F: Clone>(
|
||||||
state: &SessionState,
|
state: &SessionState,
|
||||||
merchant_id: &common_utils::id_type::MerchantId,
|
merchant_id: &common_utils::id_type::MerchantId,
|
||||||
algorithm_id: Option<String>,
|
algorithm_id: Option<common_utils::id_type::RoutingId>,
|
||||||
business_profile: &domain::BusinessProfile,
|
business_profile: &domain::BusinessProfile,
|
||||||
transaction_data: &routing::TransactionData<'_, F>,
|
transaction_data: &routing::TransactionData<'_, F>,
|
||||||
) -> RoutingResult<Vec<routing_types::RoutableConnectorChoice>> {
|
) -> RoutingResult<Vec<routing_types::RoutableConnectorChoice>> {
|
||||||
@ -352,7 +352,7 @@ pub async fn perform_static_routing_v1<F: Clone>(
|
|||||||
async fn ensure_algorithm_cached_v1(
|
async fn ensure_algorithm_cached_v1(
|
||||||
state: &SessionState,
|
state: &SessionState,
|
||||||
merchant_id: &common_utils::id_type::MerchantId,
|
merchant_id: &common_utils::id_type::MerchantId,
|
||||||
algorithm_id: &str,
|
algorithm_id: &common_utils::id_type::RoutingId,
|
||||||
profile_id: common_utils::id_type::ProfileId,
|
profile_id: common_utils::id_type::ProfileId,
|
||||||
transaction_type: &api_enums::TransactionType,
|
transaction_type: &api_enums::TransactionType,
|
||||||
) -> RoutingResult<Arc<CachedAlgorithm>> {
|
) -> RoutingResult<Arc<CachedAlgorithm>> {
|
||||||
@ -437,7 +437,7 @@ fn execute_dsl_and_get_connector_v1(
|
|||||||
pub async fn refresh_routing_cache_v1(
|
pub async fn refresh_routing_cache_v1(
|
||||||
state: &SessionState,
|
state: &SessionState,
|
||||||
key: String,
|
key: String,
|
||||||
algorithm_id: &str,
|
algorithm_id: &common_utils::id_type::RoutingId,
|
||||||
profile_id: common_utils::id_type::ProfileId,
|
profile_id: common_utils::id_type::ProfileId,
|
||||||
) -> RoutingResult<Arc<CachedAlgorithm>> {
|
) -> RoutingResult<Arc<CachedAlgorithm>> {
|
||||||
let algorithm = {
|
let algorithm = {
|
||||||
|
|||||||
@ -14,8 +14,12 @@ use super::payments;
|
|||||||
use super::payouts;
|
use super::payouts;
|
||||||
#[cfg(all(any(feature = "v1", feature = "v2"), not(feature = "routing_v2")))]
|
#[cfg(all(any(feature = "v1", feature = "v2"), not(feature = "routing_v2")))]
|
||||||
use crate::utils::ValueExt;
|
use crate::utils::ValueExt;
|
||||||
|
#[cfg(all(feature = "v2", feature = "routing_v2"))]
|
||||||
|
use crate::{
|
||||||
|
core::{admin, errors::RouterResult},
|
||||||
|
db::StorageInterface,
|
||||||
|
};
|
||||||
use crate::{
|
use crate::{
|
||||||
consts,
|
|
||||||
core::{
|
core::{
|
||||||
errors::{self, RouterResponse, StorageErrorExt},
|
errors::{self, RouterResponse, StorageErrorExt},
|
||||||
metrics, utils as core_utils,
|
metrics, utils as core_utils,
|
||||||
@ -28,11 +32,6 @@ use crate::{
|
|||||||
},
|
},
|
||||||
utils::{self, OptionExt},
|
utils::{self, OptionExt},
|
||||||
};
|
};
|
||||||
#[cfg(all(feature = "v2", feature = "routing_v2"))]
|
|
||||||
use crate::{
|
|
||||||
core::{admin, errors::RouterResult},
|
|
||||||
db::StorageInterface,
|
|
||||||
};
|
|
||||||
pub enum TransactionData<'a, F>
|
pub enum TransactionData<'a, F>
|
||||||
where
|
where
|
||||||
F: Clone,
|
F: Clone,
|
||||||
@ -53,10 +52,7 @@ impl RoutingAlgorithmUpdate {
|
|||||||
profile_id: common_utils::id_type::ProfileId,
|
profile_id: common_utils::id_type::ProfileId,
|
||||||
transaction_type: &enums::TransactionType,
|
transaction_type: &enums::TransactionType,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let algorithm_id = common_utils::generate_id(
|
let algorithm_id = common_utils::generate_routing_id_of_default_length();
|
||||||
consts::ROUTING_CONFIG_ID_LENGTH,
|
|
||||||
&format!("routing_{}", merchant_id.get_string_repr()),
|
|
||||||
);
|
|
||||||
let timestamp = common_utils::date_time::now();
|
let timestamp = common_utils::date_time::now();
|
||||||
let algo = RoutingAlgorithm {
|
let algo = RoutingAlgorithm {
|
||||||
algorithm_id,
|
algorithm_id,
|
||||||
@ -74,7 +70,7 @@ impl RoutingAlgorithmUpdate {
|
|||||||
}
|
}
|
||||||
pub async fn fetch_routing_algo(
|
pub async fn fetch_routing_algo(
|
||||||
merchant_id: &common_utils::id_type::MerchantId,
|
merchant_id: &common_utils::id_type::MerchantId,
|
||||||
algorithm_id: &str,
|
algorithm_id: &common_utils::id_type::RoutingId,
|
||||||
db: &dyn StorageInterface,
|
db: &dyn StorageInterface,
|
||||||
) -> RouterResult<Self> {
|
) -> RouterResult<Self> {
|
||||||
let routing_algo = db
|
let routing_algo = db
|
||||||
@ -215,10 +211,7 @@ pub async fn create_routing_algorithm_under_profile(
|
|||||||
})
|
})
|
||||||
.attach_printable("Algorithm of config not given")?;
|
.attach_printable("Algorithm of config not given")?;
|
||||||
|
|
||||||
let algorithm_id = common_utils::generate_id(
|
let algorithm_id = common_utils::generate_routing_id_of_default_length();
|
||||||
consts::ROUTING_CONFIG_ID_LENGTH,
|
|
||||||
&format!("routing_{}", merchant_account.get_id().get_string_repr()),
|
|
||||||
);
|
|
||||||
|
|
||||||
let profile_id = request
|
let profile_id = request
|
||||||
.profile_id
|
.profile_id
|
||||||
@ -280,7 +273,7 @@ pub async fn link_routing_config_under_profile(
|
|||||||
merchant_account: domain::MerchantAccount,
|
merchant_account: domain::MerchantAccount,
|
||||||
key_store: domain::MerchantKeyStore,
|
key_store: domain::MerchantKeyStore,
|
||||||
profile_id: common_utils::id_type::ProfileId,
|
profile_id: common_utils::id_type::ProfileId,
|
||||||
algorithm_id: String,
|
algorithm_id: common_utils::id_type::RoutingId,
|
||||||
transaction_type: &enums::TransactionType,
|
transaction_type: &enums::TransactionType,
|
||||||
) -> RouterResponse<routing_types::RoutingDictionaryRecord> {
|
) -> RouterResponse<routing_types::RoutingDictionaryRecord> {
|
||||||
metrics::ROUTING_LINK_CONFIG.add(&metrics::CONTEXT, 1, &[]);
|
metrics::ROUTING_LINK_CONFIG.add(&metrics::CONTEXT, 1, &[]);
|
||||||
@ -352,7 +345,7 @@ pub async fn link_routing_config(
|
|||||||
state: SessionState,
|
state: SessionState,
|
||||||
merchant_account: domain::MerchantAccount,
|
merchant_account: domain::MerchantAccount,
|
||||||
key_store: domain::MerchantKeyStore,
|
key_store: domain::MerchantKeyStore,
|
||||||
algorithm_id: String,
|
algorithm_id: common_utils::id_type::RoutingId,
|
||||||
transaction_type: &enums::TransactionType,
|
transaction_type: &enums::TransactionType,
|
||||||
) -> RouterResponse<routing_types::RoutingDictionaryRecord> {
|
) -> RouterResponse<routing_types::RoutingDictionaryRecord> {
|
||||||
metrics::ROUTING_LINK_CONFIG.add(&metrics::CONTEXT, 1, &[]);
|
metrics::ROUTING_LINK_CONFIG.add(&metrics::CONTEXT, 1, &[]);
|
||||||
@ -428,7 +421,7 @@ pub async fn retrieve_routing_algorithm_from_algorithm_id(
|
|||||||
state: SessionState,
|
state: SessionState,
|
||||||
merchant_account: domain::MerchantAccount,
|
merchant_account: domain::MerchantAccount,
|
||||||
key_store: domain::MerchantKeyStore,
|
key_store: domain::MerchantKeyStore,
|
||||||
algorithm_id: String,
|
algorithm_id: common_utils::id_type::RoutingId,
|
||||||
) -> RouterResponse<routing_types::MerchantRoutingAlgorithm> {
|
) -> RouterResponse<routing_types::MerchantRoutingAlgorithm> {
|
||||||
metrics::ROUTING_RETRIEVE_CONFIG.add(&metrics::CONTEXT, 1, &[]);
|
metrics::ROUTING_RETRIEVE_CONFIG.add(&metrics::CONTEXT, 1, &[]);
|
||||||
let db = state.store.as_ref();
|
let db = state.store.as_ref();
|
||||||
@ -461,7 +454,7 @@ pub async fn retrieve_routing_algorithm_from_algorithm_id(
|
|||||||
state: SessionState,
|
state: SessionState,
|
||||||
merchant_account: domain::MerchantAccount,
|
merchant_account: domain::MerchantAccount,
|
||||||
key_store: domain::MerchantKeyStore,
|
key_store: domain::MerchantKeyStore,
|
||||||
algorithm_id: String,
|
algorithm_id: common_utils::id_type::RoutingId,
|
||||||
) -> RouterResponse<routing_types::MerchantRoutingAlgorithm> {
|
) -> RouterResponse<routing_types::MerchantRoutingAlgorithm> {
|
||||||
metrics::ROUTING_RETRIEVE_CONFIG.add(&metrics::CONTEXT, 1, &[]);
|
metrics::ROUTING_RETRIEVE_CONFIG.add(&metrics::CONTEXT, 1, &[]);
|
||||||
let db = state.store.as_ref();
|
let db = state.store.as_ref();
|
||||||
|
|||||||
@ -2495,7 +2495,7 @@ impl RoutingAlgorithmInterface for KafkaStore {
|
|||||||
async fn find_routing_algorithm_by_profile_id_algorithm_id(
|
async fn find_routing_algorithm_by_profile_id_algorithm_id(
|
||||||
&self,
|
&self,
|
||||||
profile_id: &id_type::ProfileId,
|
profile_id: &id_type::ProfileId,
|
||||||
algorithm_id: &str,
|
algorithm_id: &id_type::RoutingId,
|
||||||
) -> CustomResult<storage::RoutingAlgorithm, errors::StorageError> {
|
) -> CustomResult<storage::RoutingAlgorithm, errors::StorageError> {
|
||||||
self.diesel_store
|
self.diesel_store
|
||||||
.find_routing_algorithm_by_profile_id_algorithm_id(profile_id, algorithm_id)
|
.find_routing_algorithm_by_profile_id_algorithm_id(profile_id, algorithm_id)
|
||||||
@ -2504,7 +2504,7 @@ impl RoutingAlgorithmInterface for KafkaStore {
|
|||||||
|
|
||||||
async fn find_routing_algorithm_by_algorithm_id_merchant_id(
|
async fn find_routing_algorithm_by_algorithm_id_merchant_id(
|
||||||
&self,
|
&self,
|
||||||
algorithm_id: &str,
|
algorithm_id: &id_type::RoutingId,
|
||||||
merchant_id: &id_type::MerchantId,
|
merchant_id: &id_type::MerchantId,
|
||||||
) -> CustomResult<storage::RoutingAlgorithm, errors::StorageError> {
|
) -> CustomResult<storage::RoutingAlgorithm, errors::StorageError> {
|
||||||
self.diesel_store
|
self.diesel_store
|
||||||
@ -2514,7 +2514,7 @@ impl RoutingAlgorithmInterface for KafkaStore {
|
|||||||
|
|
||||||
async fn find_routing_algorithm_metadata_by_algorithm_id_profile_id(
|
async fn find_routing_algorithm_metadata_by_algorithm_id_profile_id(
|
||||||
&self,
|
&self,
|
||||||
algorithm_id: &str,
|
algorithm_id: &id_type::RoutingId,
|
||||||
profile_id: &id_type::ProfileId,
|
profile_id: &id_type::ProfileId,
|
||||||
) -> CustomResult<storage::RoutingProfileMetadata, errors::StorageError> {
|
) -> CustomResult<storage::RoutingProfileMetadata, errors::StorageError> {
|
||||||
self.diesel_store
|
self.diesel_store
|
||||||
|
|||||||
@ -21,18 +21,18 @@ pub trait RoutingAlgorithmInterface {
|
|||||||
async fn find_routing_algorithm_by_profile_id_algorithm_id(
|
async fn find_routing_algorithm_by_profile_id_algorithm_id(
|
||||||
&self,
|
&self,
|
||||||
profile_id: &common_utils::id_type::ProfileId,
|
profile_id: &common_utils::id_type::ProfileId,
|
||||||
algorithm_id: &str,
|
algorithm_id: &common_utils::id_type::RoutingId,
|
||||||
) -> StorageResult<routing_storage::RoutingAlgorithm>;
|
) -> StorageResult<routing_storage::RoutingAlgorithm>;
|
||||||
|
|
||||||
async fn find_routing_algorithm_by_algorithm_id_merchant_id(
|
async fn find_routing_algorithm_by_algorithm_id_merchant_id(
|
||||||
&self,
|
&self,
|
||||||
algorithm_id: &str,
|
algorithm_id: &common_utils::id_type::RoutingId,
|
||||||
merchant_id: &common_utils::id_type::MerchantId,
|
merchant_id: &common_utils::id_type::MerchantId,
|
||||||
) -> StorageResult<routing_storage::RoutingAlgorithm>;
|
) -> StorageResult<routing_storage::RoutingAlgorithm>;
|
||||||
|
|
||||||
async fn find_routing_algorithm_metadata_by_algorithm_id_profile_id(
|
async fn find_routing_algorithm_metadata_by_algorithm_id_profile_id(
|
||||||
&self,
|
&self,
|
||||||
algorithm_id: &str,
|
algorithm_id: &common_utils::id_type::RoutingId,
|
||||||
profile_id: &common_utils::id_type::ProfileId,
|
profile_id: &common_utils::id_type::ProfileId,
|
||||||
) -> StorageResult<routing_storage::RoutingProfileMetadata>;
|
) -> StorageResult<routing_storage::RoutingProfileMetadata>;
|
||||||
|
|
||||||
@ -77,7 +77,7 @@ impl RoutingAlgorithmInterface for Store {
|
|||||||
async fn find_routing_algorithm_by_profile_id_algorithm_id(
|
async fn find_routing_algorithm_by_profile_id_algorithm_id(
|
||||||
&self,
|
&self,
|
||||||
profile_id: &common_utils::id_type::ProfileId,
|
profile_id: &common_utils::id_type::ProfileId,
|
||||||
algorithm_id: &str,
|
algorithm_id: &common_utils::id_type::RoutingId,
|
||||||
) -> StorageResult<routing_storage::RoutingAlgorithm> {
|
) -> StorageResult<routing_storage::RoutingAlgorithm> {
|
||||||
let conn = connection::pg_connection_write(self).await?;
|
let conn = connection::pg_connection_write(self).await?;
|
||||||
routing_storage::RoutingAlgorithm::find_by_algorithm_id_profile_id(
|
routing_storage::RoutingAlgorithm::find_by_algorithm_id_profile_id(
|
||||||
@ -92,7 +92,7 @@ impl RoutingAlgorithmInterface for Store {
|
|||||||
#[instrument(skip_all)]
|
#[instrument(skip_all)]
|
||||||
async fn find_routing_algorithm_by_algorithm_id_merchant_id(
|
async fn find_routing_algorithm_by_algorithm_id_merchant_id(
|
||||||
&self,
|
&self,
|
||||||
algorithm_id: &str,
|
algorithm_id: &common_utils::id_type::RoutingId,
|
||||||
merchant_id: &common_utils::id_type::MerchantId,
|
merchant_id: &common_utils::id_type::MerchantId,
|
||||||
) -> StorageResult<routing_storage::RoutingAlgorithm> {
|
) -> StorageResult<routing_storage::RoutingAlgorithm> {
|
||||||
let conn = connection::pg_connection_write(self).await?;
|
let conn = connection::pg_connection_write(self).await?;
|
||||||
@ -108,7 +108,7 @@ impl RoutingAlgorithmInterface for Store {
|
|||||||
#[instrument(skip_all)]
|
#[instrument(skip_all)]
|
||||||
async fn find_routing_algorithm_metadata_by_algorithm_id_profile_id(
|
async fn find_routing_algorithm_metadata_by_algorithm_id_profile_id(
|
||||||
&self,
|
&self,
|
||||||
algorithm_id: &str,
|
algorithm_id: &common_utils::id_type::RoutingId,
|
||||||
profile_id: &common_utils::id_type::ProfileId,
|
profile_id: &common_utils::id_type::ProfileId,
|
||||||
) -> StorageResult<routing_storage::RoutingProfileMetadata> {
|
) -> StorageResult<routing_storage::RoutingProfileMetadata> {
|
||||||
let conn = connection::pg_connection_write(self).await?;
|
let conn = connection::pg_connection_write(self).await?;
|
||||||
@ -186,14 +186,14 @@ impl RoutingAlgorithmInterface for MockDb {
|
|||||||
async fn find_routing_algorithm_by_profile_id_algorithm_id(
|
async fn find_routing_algorithm_by_profile_id_algorithm_id(
|
||||||
&self,
|
&self,
|
||||||
_profile_id: &common_utils::id_type::ProfileId,
|
_profile_id: &common_utils::id_type::ProfileId,
|
||||||
_algorithm_id: &str,
|
_algorithm_id: &common_utils::id_type::RoutingId,
|
||||||
) -> StorageResult<routing_storage::RoutingAlgorithm> {
|
) -> StorageResult<routing_storage::RoutingAlgorithm> {
|
||||||
Err(errors::StorageError::MockDbError)?
|
Err(errors::StorageError::MockDbError)?
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn find_routing_algorithm_by_algorithm_id_merchant_id(
|
async fn find_routing_algorithm_by_algorithm_id_merchant_id(
|
||||||
&self,
|
&self,
|
||||||
_algorithm_id: &str,
|
_algorithm_id: &common_utils::id_type::RoutingId,
|
||||||
_merchant_id: &common_utils::id_type::MerchantId,
|
_merchant_id: &common_utils::id_type::MerchantId,
|
||||||
) -> StorageResult<routing_storage::RoutingAlgorithm> {
|
) -> StorageResult<routing_storage::RoutingAlgorithm> {
|
||||||
Err(errors::StorageError::MockDbError)?
|
Err(errors::StorageError::MockDbError)?
|
||||||
@ -201,7 +201,7 @@ impl RoutingAlgorithmInterface for MockDb {
|
|||||||
|
|
||||||
async fn find_routing_algorithm_metadata_by_algorithm_id_profile_id(
|
async fn find_routing_algorithm_metadata_by_algorithm_id_profile_id(
|
||||||
&self,
|
&self,
|
||||||
_algorithm_id: &str,
|
_algorithm_id: &common_utils::id_type::RoutingId,
|
||||||
_profile_id: &common_utils::id_type::ProfileId,
|
_profile_id: &common_utils::id_type::ProfileId,
|
||||||
) -> StorageResult<routing_storage::RoutingProfileMetadata> {
|
) -> StorageResult<routing_storage::RoutingProfileMetadata> {
|
||||||
Err(errors::StorageError::MockDbError)?
|
Err(errors::StorageError::MockDbError)?
|
||||||
|
|||||||
@ -60,7 +60,7 @@ pub async fn routing_create_config(
|
|||||||
pub async fn routing_link_config(
|
pub async fn routing_link_config(
|
||||||
state: web::Data<AppState>,
|
state: web::Data<AppState>,
|
||||||
req: HttpRequest,
|
req: HttpRequest,
|
||||||
path: web::Path<String>,
|
path: web::Path<common_utils::id_type::RoutingId>,
|
||||||
transaction_type: &enums::TransactionType,
|
transaction_type: &enums::TransactionType,
|
||||||
) -> impl Responder {
|
) -> impl Responder {
|
||||||
let flow = Flow::RoutingLinkConfig;
|
let flow = Flow::RoutingLinkConfig;
|
||||||
@ -139,7 +139,7 @@ pub async fn routing_link_config(
|
|||||||
pub async fn routing_retrieve_config(
|
pub async fn routing_retrieve_config(
|
||||||
state: web::Data<AppState>,
|
state: web::Data<AppState>,
|
||||||
req: HttpRequest,
|
req: HttpRequest,
|
||||||
path: web::Path<String>,
|
path: web::Path<common_utils::id_type::RoutingId>,
|
||||||
) -> impl Responder {
|
) -> impl Responder {
|
||||||
let algorithm_id = path.into_inner();
|
let algorithm_id = path.into_inner();
|
||||||
let flow = Flow::RoutingRetrieveConfig;
|
let flow = Flow::RoutingRetrieveConfig;
|
||||||
|
|||||||
Reference in New Issue
Block a user