mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-01 19:42:27 +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:
@ -4073,7 +4073,7 @@ impl BusinessProfileWrapper {
|
||||
db: &dyn StorageInterface,
|
||||
key_manager_state: &KeyManagerState,
|
||||
merchant_key_store: &domain::MerchantKeyStore,
|
||||
algorithm_id: String,
|
||||
algorithm_id: common_utils::id_type::RoutingId,
|
||||
transaction_type: &storage::enums::TransactionType,
|
||||
) -> RouterResult<()> {
|
||||
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>(
|
||||
&'a self,
|
||||
transaction_data: &'a routing::TransactionData<'_, F>,
|
||||
) -> Option<String>
|
||||
) -> Option<id_type::RoutingId>
|
||||
where
|
||||
F: Send + Clone,
|
||||
{
|
||||
|
||||
@ -114,7 +114,7 @@ impl Default for MerchantAccountRoutingAlgorithm {
|
||||
#[derive(Debug, serde::Serialize, serde::Deserialize)]
|
||||
#[serde(untagged)]
|
||||
enum MerchantAccountRoutingAlgorithm {
|
||||
V1(Option<String>),
|
||||
V1(Option<common_utils::id_type::RoutingId>),
|
||||
}
|
||||
|
||||
#[cfg(feature = "payouts")]
|
||||
@ -289,7 +289,7 @@ where
|
||||
pub async fn perform_static_routing_v1<F: Clone>(
|
||||
state: &SessionState,
|
||||
merchant_id: &common_utils::id_type::MerchantId,
|
||||
algorithm_id: Option<String>,
|
||||
algorithm_id: Option<common_utils::id_type::RoutingId>,
|
||||
business_profile: &domain::BusinessProfile,
|
||||
transaction_data: &routing::TransactionData<'_, F>,
|
||||
) -> RoutingResult<Vec<routing_types::RoutableConnectorChoice>> {
|
||||
@ -352,7 +352,7 @@ pub async fn perform_static_routing_v1<F: Clone>(
|
||||
async fn ensure_algorithm_cached_v1(
|
||||
state: &SessionState,
|
||||
merchant_id: &common_utils::id_type::MerchantId,
|
||||
algorithm_id: &str,
|
||||
algorithm_id: &common_utils::id_type::RoutingId,
|
||||
profile_id: common_utils::id_type::ProfileId,
|
||||
transaction_type: &api_enums::TransactionType,
|
||||
) -> RoutingResult<Arc<CachedAlgorithm>> {
|
||||
@ -437,7 +437,7 @@ fn execute_dsl_and_get_connector_v1(
|
||||
pub async fn refresh_routing_cache_v1(
|
||||
state: &SessionState,
|
||||
key: String,
|
||||
algorithm_id: &str,
|
||||
algorithm_id: &common_utils::id_type::RoutingId,
|
||||
profile_id: common_utils::id_type::ProfileId,
|
||||
) -> RoutingResult<Arc<CachedAlgorithm>> {
|
||||
let algorithm = {
|
||||
|
||||
@ -14,8 +14,12 @@ use super::payments;
|
||||
use super::payouts;
|
||||
#[cfg(all(any(feature = "v1", feature = "v2"), not(feature = "routing_v2")))]
|
||||
use crate::utils::ValueExt;
|
||||
#[cfg(all(feature = "v2", feature = "routing_v2"))]
|
||||
use crate::{
|
||||
core::{admin, errors::RouterResult},
|
||||
db::StorageInterface,
|
||||
};
|
||||
use crate::{
|
||||
consts,
|
||||
core::{
|
||||
errors::{self, RouterResponse, StorageErrorExt},
|
||||
metrics, utils as core_utils,
|
||||
@ -28,11 +32,6 @@ use crate::{
|
||||
},
|
||||
utils::{self, OptionExt},
|
||||
};
|
||||
#[cfg(all(feature = "v2", feature = "routing_v2"))]
|
||||
use crate::{
|
||||
core::{admin, errors::RouterResult},
|
||||
db::StorageInterface,
|
||||
};
|
||||
pub enum TransactionData<'a, F>
|
||||
where
|
||||
F: Clone,
|
||||
@ -53,10 +52,7 @@ impl RoutingAlgorithmUpdate {
|
||||
profile_id: common_utils::id_type::ProfileId,
|
||||
transaction_type: &enums::TransactionType,
|
||||
) -> Self {
|
||||
let algorithm_id = common_utils::generate_id(
|
||||
consts::ROUTING_CONFIG_ID_LENGTH,
|
||||
&format!("routing_{}", merchant_id.get_string_repr()),
|
||||
);
|
||||
let algorithm_id = common_utils::generate_routing_id_of_default_length();
|
||||
let timestamp = common_utils::date_time::now();
|
||||
let algo = RoutingAlgorithm {
|
||||
algorithm_id,
|
||||
@ -74,7 +70,7 @@ impl RoutingAlgorithmUpdate {
|
||||
}
|
||||
pub async fn fetch_routing_algo(
|
||||
merchant_id: &common_utils::id_type::MerchantId,
|
||||
algorithm_id: &str,
|
||||
algorithm_id: &common_utils::id_type::RoutingId,
|
||||
db: &dyn StorageInterface,
|
||||
) -> RouterResult<Self> {
|
||||
let routing_algo = db
|
||||
@ -215,10 +211,7 @@ pub async fn create_routing_algorithm_under_profile(
|
||||
})
|
||||
.attach_printable("Algorithm of config not given")?;
|
||||
|
||||
let algorithm_id = common_utils::generate_id(
|
||||
consts::ROUTING_CONFIG_ID_LENGTH,
|
||||
&format!("routing_{}", merchant_account.get_id().get_string_repr()),
|
||||
);
|
||||
let algorithm_id = common_utils::generate_routing_id_of_default_length();
|
||||
|
||||
let profile_id = request
|
||||
.profile_id
|
||||
@ -280,7 +273,7 @@ pub async fn link_routing_config_under_profile(
|
||||
merchant_account: domain::MerchantAccount,
|
||||
key_store: domain::MerchantKeyStore,
|
||||
profile_id: common_utils::id_type::ProfileId,
|
||||
algorithm_id: String,
|
||||
algorithm_id: common_utils::id_type::RoutingId,
|
||||
transaction_type: &enums::TransactionType,
|
||||
) -> RouterResponse<routing_types::RoutingDictionaryRecord> {
|
||||
metrics::ROUTING_LINK_CONFIG.add(&metrics::CONTEXT, 1, &[]);
|
||||
@ -352,7 +345,7 @@ pub async fn link_routing_config(
|
||||
state: SessionState,
|
||||
merchant_account: domain::MerchantAccount,
|
||||
key_store: domain::MerchantKeyStore,
|
||||
algorithm_id: String,
|
||||
algorithm_id: common_utils::id_type::RoutingId,
|
||||
transaction_type: &enums::TransactionType,
|
||||
) -> RouterResponse<routing_types::RoutingDictionaryRecord> {
|
||||
metrics::ROUTING_LINK_CONFIG.add(&metrics::CONTEXT, 1, &[]);
|
||||
@ -428,7 +421,7 @@ pub async fn retrieve_routing_algorithm_from_algorithm_id(
|
||||
state: SessionState,
|
||||
merchant_account: domain::MerchantAccount,
|
||||
key_store: domain::MerchantKeyStore,
|
||||
algorithm_id: String,
|
||||
algorithm_id: common_utils::id_type::RoutingId,
|
||||
) -> RouterResponse<routing_types::MerchantRoutingAlgorithm> {
|
||||
metrics::ROUTING_RETRIEVE_CONFIG.add(&metrics::CONTEXT, 1, &[]);
|
||||
let db = state.store.as_ref();
|
||||
@ -461,7 +454,7 @@ pub async fn retrieve_routing_algorithm_from_algorithm_id(
|
||||
state: SessionState,
|
||||
merchant_account: domain::MerchantAccount,
|
||||
key_store: domain::MerchantKeyStore,
|
||||
algorithm_id: String,
|
||||
algorithm_id: common_utils::id_type::RoutingId,
|
||||
) -> RouterResponse<routing_types::MerchantRoutingAlgorithm> {
|
||||
metrics::ROUTING_RETRIEVE_CONFIG.add(&metrics::CONTEXT, 1, &[]);
|
||||
let db = state.store.as_ref();
|
||||
|
||||
Reference in New Issue
Block a user