Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
feat(platform): platform-connected support for routing and surcharge (#12263)
Apoorv Dixit5d4a92b0d37c
diff --git a/crates/diesel_models/src/query/routing_algorithm.rs b/crates/diesel_models/src/query/routing_algorithm.rsindex c4d56736aa..227ef45a9f 100644--- a/crates/diesel_models/src/query/routing_algorithm.rs+++ b/crates/diesel_models/src/query/routing_algorithm.rs@@ -31,6 +31,20 @@ impl RoutingAlgorithm {.await}+ pub async fn find_by_algorithm_id_processor_merchant_id(+ conn: &PgPooledConn,+ algorithm_id: &common_utils::id_type::RoutingId,+ processor_merchant_id: &common_utils::id_type::MerchantId,+ ) -> StorageResult<Self> {+ generics::generic_find_one::<<Self as HasTable>::Table, _, _>(+ conn,+ dsl::algorithm_id+ .eq(algorithm_id.to_owned())+ .and(dsl::processor_merchant_id.eq(processor_merchant_id.to_owned())),+ )+ .await+ }+pub async fn find_by_algorithm_id_profile_id(conn: &PgPooledConn,algorithm_id: &common_utils::id_type::RoutingId,@@ -183,7 +197,13 @@ impl RoutingAlgorithm {dsl::modified_at,dsl::algorithm_for,))- .filter(dsl::merchant_id.eq(merchant_id.to_owned()))+ .filter(+ dsl::processor_merchant_id.eq(merchant_id.to_owned()).or(+ dsl::processor_merchant_id+ .is_null()+ .and(dsl::merchant_id.eq(merchant_id.to_owned())),+ ),+ ).limit(limit).offset(offset).order(dsl::modified_at.desc())@@ -244,7 +264,13 @@ impl RoutingAlgorithm {dsl::modified_at,dsl::algorithm_for,))- .filter(dsl::merchant_id.eq(merchant_id.to_owned()))+ .filter(+ dsl::processor_merchant_id.eq(merchant_id.to_owned()).or(+ dsl::processor_merchant_id+ .is_null()+ .and(dsl::merchant_id.eq(merchant_id.to_owned())),+ ),+ ).filter(dsl::algorithm_for.eq(transaction_type.to_owned())).limit(limit).offset(offset)diff --git a/crates/diesel_models/src/routing_algorithm.rs b/crates/diesel_models/src/routing_algorithm.rsindex 2844aeb16f..986ed39d81 100644--- a/crates/diesel_models/src/routing_algorithm.rs+++ b/crates/diesel_models/src/routing_algorithm.rs@@ -18,6 +18,8 @@ pub struct RoutingAlgorithm {pub modified_at: time::PrimitiveDateTime,pub algorithm_for: enums::TransactionType,pub decision_engine_routing_id: Option<String>,+ pub processor_merchant_id: Option<id_type::MerchantId>,+ pub created_by: Option<String>,}pub struct RoutingAlgorithmMetadata {diff --git a/crates/diesel_models/src/schema.rs b/crates/diesel_models/src/schema.rsindex 3a1a1eb5e6..f70e99322d 100644--- a/crates/diesel_models/src/schema.rs+++ b/crates/diesel_models/src/schema.rs@@ -1748,6 +1748,10 @@ diesel::table! {algorithm_for -> TransactionType,#[max_length = 64]decision_engine_routing_id -> Nullable<Varchar>,+ #[max_length = 64]+ processor_merchant_id -> Nullable<Varchar>,+ #[max_length = 255]+ created_by -> Nullable<Varchar>,}}diff --git a/crates/diesel_models/src/schema_v2.rs b/crates/diesel_models/src/schema_v2.rsindex 6eacd260aa..8ac0fd0428 100644--- a/crates/diesel_models/src/schema_v2.rs+++ b/crates/diesel_models/src/schema_v2.rs@@ -1684,6 +1684,10 @@ diesel::table! {algorithm_for -> TransactionType,#[max_length = 64]decision_engine_routing_id -> Nullable<Varchar>,+ #[max_length = 64]+ processor_merchant_id -> Nullable<Varchar>,+ #[max_length = 255]+ created_by -> Nullable<Varchar>,}}diff --git a/crates/router/src/core/conditional_config.rs b/crates/router/src/core/conditional_config.rsindex 3d39b565d3..8d96646ee9 100644--- a/crates/router/src/core/conditional_config.rs+++ b/crates/router/src/core/conditional_config.rs@@ -65,7 +65,7 @@ pub async fn upsert_conditional_config(#[cfg(feature = "v1")]pub async fn upsert_conditional_config(state: SessionState,- platform: domain::Platform,+ processor: domain::Processor,request: DecisionManager,) -> RouterResponse<DecisionManagerRecord> {use common_utils::ext_traits::{Encode, OptionExt, ValueExt};@@ -102,8 +102,7 @@ pub async fn upsert_conditional_config(}};let timestamp = common_utils::date_time::now_unix_timestamp();- let mut algo_id: api_models::routing::RoutingAlgorithmRef = platform- .get_processor()+ let mut algo_id: api_models::routing::RoutingAlgorithmRef = processor.get_account().routing_algorithm.clone()@@ -113,8 +112,7 @@ pub async fn upsert_conditional_config(.attach_printable("Could not decode the routing algorithm")?.unwrap_or_default();- let key = platform- .get_processor()+ let key = processor.get_account().get_id().get_payment_config_routing_id();@@ -159,7 +157,7 @@ pub async fn upsert_conditional_config(let config_key = cache::CacheKind::DecisionManager(key.into());update_merchant_active_algorithm_ref(&state,- platform.get_processor().get_key_store(),+ processor.get_key_store(),config_key,algo_id,)@@ -200,7 +198,7 @@ pub async fn upsert_conditional_config(let config_key = cache::CacheKind::DecisionManager(key.into());update_merchant_active_algorithm_ref(&state,- platform.get_processor().get_key_store(),+ processor.get_key_store(),config_key,algo_id,)@@ -219,7 +217,7 @@ pub async fn upsert_conditional_config(#[cfg(feature = "v2")]pub async fn delete_conditional_config(_state: SessionState,- _platform: domain::Platform,+ _processor: domain::Processor,) -> RouterResponse<()> {todo!()}@@ -227,7 +225,7 @@ pub async fn delete_conditional_config(#[cfg(feature = "v1")]pub async fn delete_conditional_config(state: SessionState,- platform: domain::Platform,+ processor: domain::Processor,) -> RouterResponse<()> {use common_utils::ext_traits::ValueExt;use storage_impl::redis::cache;@@ -235,13 +233,11 @@ pub async fn delete_conditional_config(use super::routing::helpers::update_merchant_active_algorithm_ref;let db = state.store.as_ref();- let key = platform- .get_processor()+ let key = processor.get_account().get_id().get_payment_config_routing_id();- let mut algo_id: api_models::routing::RoutingAlgorithmRef = platform- .get_processor()+ let mut algo_id: api_models::routing::RoutingAlgorithmRef = processor.get_account().routing_algorithm.clone()@@ -252,15 +248,10 @@ pub async fn delete_conditional_config(.unwrap_or_default();algo_id.config_algo_id = None;let config_key = cache::CacheKind::DecisionManager(key.clone().into());- update_merchant_active_algorithm_ref(- &state,- platform.get_processor().get_key_store(),- config_key,- algo_id,- )- .await- .change_context(errors::ApiErrorResponse::InternalServerError)- .attach_printable("Failed to update deleted algorithm ref")?;+ update_merchant_active_algorithm_ref(&state, processor.get_key_store(), config_key, algo_id)+ .await+ .change_context(errors::ApiErrorResponse::InternalServerError)+ .attach_printable("Failed to update deleted algorithm ref")?;db.delete_config_by_key(&key).await@@ -272,11 +263,10 @@ pub async fn delete_conditional_config(#[cfg(feature = "v1")]pub async fn retrieve_conditional_config(state: SessionState,- platform: domain::Platform,+ processor: domain::Processor,) -> RouterResponse<DecisionManagerResponse> {let db = state.store.as_ref();- let algorithm_id = platform- .get_processor()+ let algorithm_id = processor.get_account().get_id().get_payment_config_routing_id();diff --git a/crates/router/src/core/routing.rs b/crates/router/src/core/routing.rsindex 2a22001c48..a62a15d6d0 100644--- a/crates/router/src/core/routing.rs+++ b/crates/router/src/core/routing.rs@@ -116,7 +116,7 @@ struct RoutingAlgorithmUpdate(RoutingAlgorithm);impl RoutingAlgorithmUpdate {pub fn create_new_routing_algorithm(request: &routing_types::RoutingConfigRequest,- merchant_id: &common_utils::id_type::MerchantId,+ platform: &domain::Platform,profile_id: common_utils::id_type::ProfileId,transaction_type: enums::TransactionType,) -> Self {@@ -125,7 +125,7 @@ impl RoutingAlgorithmUpdate {let algo = RoutingAlgorithm {algorithm_id,profile_id,- merchant_id: merchant_id.clone(),+ merchant_id: platform.get_provider().get_account().get_id().clone(),name: request.name.clone(),description: Some(request.description.clone()),kind: request.algorithm.get_kind().foreign_into(),@@ -134,16 +134,24 @@ impl RoutingAlgorithmUpdate {modified_at: timestamp,algorithm_for: transaction_type,decision_engine_routing_id: None,+ processor_merchant_id: Some(platform.get_processor().get_account().get_id().clone()),+ created_by: platform+ .get_initiator()+ .and_then(|initiator| initiator.to_created_by())+ .map(|created_by| created_by.to_string()),};Self(algo)}pub async fn fetch_routing_algo(- merchant_id: &common_utils::id_type::MerchantId,+ processor_merchant_id: &common_utils::id_type::MerchantId,algorithm_id: &common_utils::id_type::RoutingId,db: &dyn StorageInterface,) -> RouterResult<Self> {let routing_algo = db- .find_routing_algorithm_by_algorithm_id_merchant_id(algorithm_id, merchant_id)+ .find_routing_algorithm_by_algorithm_id_processor_merchant_id(+ algorithm_id,+ processor_merchant_id,+ ).await.change_context(errors::ApiErrorResponse::ResourceIdNotFound)?;Ok(Self(routing_algo))@@ -276,26 +284,24 @@ pub async fn create_routing_algorithm_under_profile() -> RouterResponse<routing_types::RoutingDictionaryRecord> {metrics::ROUTING_CREATE_REQUEST_RECEIVED.add(1, &[]);let db = &*state.store;+ let processor = platform.get_processor();- let business_profile = core_utils::validate_and_get_business_profile(- db,- platform.get_processor(),- Some(&request.profile_id),- )- .await?- .get_required_value("Profile")?;- let merchant_id = platform.get_processor().get_account().get_id();+ let business_profile =+ core_utils::validate_and_get_business_profile(db, processor, Some(&request.profile_id))+ .await?+ .get_required_value("Profile")?;+ let processor_merchant_id = processor.get_account().get_id();core_utils::validate_profile_id_from_auth_layer(authentication_profile_id, &business_profile)?;let all_mcas = state.store.find_merchant_connector_account_by_merchant_id_and_disabled_list(- merchant_id,+ processor_merchant_id,true,- platform.get_processor().get_key_store(),+ processor.get_key_store(),).await.change_context(errors::ApiErrorResponse::MerchantConnectorAccountNotFound {- id: merchant_id.get_string_repr().to_owned(),+ id: processor_merchant_id.get_string_repr().to_owned(),})?;let name_mca_id_set = helpers::ConnectNameAndMCAIdForProfile(@@ -318,7 +324,7 @@ pub async fn create_routing_algorithm_under_profile(let algo = RoutingAlgorithmUpdate::create_new_routing_algorithm(&request,- platform.get_processor().get_account().get_id(),+ &platform,business_profile.get_id().to_owned(),transaction_type,);@@ -348,6 +354,8 @@ pub async fn create_routing_algorithm_under_profile(metrics::ROUTING_CREATE_REQUEST_RECEIVED.add(1, &[]);let db = state.store.as_ref();+ let processor = platform.get_processor();+ let initiator = platform.get_initiator();let name = request.name@@ -382,21 +390,18 @@ pub async fn create_routing_algorithm_under_profile(}).attach_printable("Profile_id not provided")?;- let business_profile = core_utils::validate_and_get_business_profile(- db,- platform.get_processor(),- Some(&profile_id),- )- .await?- .get_required_value("Profile")?;+ let business_profile =+ core_utils::validate_and_get_business_profile(db, processor, Some(&profile_id))+ .await?+ .get_required_value("Profile")?;core_utils::validate_profile_id_from_auth_layer(authentication_profile_id, &business_profile)?;if algorithm.should_validate_connectors_in_routing_config() {helpers::validate_connectors_in_routing_config(&state,- platform.get_processor().get_key_store(),- platform.get_processor().get_account().get_id(),+ processor.get_key_store(),+ processor.get_account().get_id(),&profile_id,&algorithm,)@@ -489,7 +494,7 @@ pub async fn create_routing_algorithm_under_profile(let algo = RoutingAlgorithm {algorithm_id: algorithm_id.clone(),profile_id,- merchant_id: platform.get_processor().get_account().get_id().to_owned(),+ merchant_id: platform.get_provider().get_account().get_id().to_owned(),name: name.to_string(),description: Some(description.clone()),kind: algorithm.get_kind().foreign_into(),@@ -498,6 +503,10 @@ pub async fn create_routing_algorithm_under_profile(modified_at: timestamp,algorithm_for: transaction_type.to_owned(),decision_engine_routing_id,+ processor_merchant_id: Some(processor.get_account().get_id().to_owned()),+ created_by: initiator+ .and_then(|initiator| initiator.to_created_by())+ .map(|created_by| created_by.to_string()),};let record = db.insert_routing_algorithm(algo)@@ -513,7 +522,7 @@ pub async fn create_routing_algorithm_under_profile(#[cfg(feature = "v2")]pub async fn link_routing_config_under_profile(state: SessionState,- platform: domain::Platform,+ processor: domain::Processor,profile_id: common_utils::id_type::ProfileId,algorithm_id: common_utils::id_type::RoutingId,transaction_type: &enums::TransactionType,@@ -523,7 +532,7 @@ pub async fn link_routing_config_under_profile(let key_manager_state = &(&state).into();let routing_algorithm = RoutingAlgorithmUpdate::fetch_routing_algo(- platform.get_processor().get_account().get_id(),+ processor.get_account().get_id(),&algorithm_id,db,)@@ -535,13 +544,10 @@ pub async fn link_routing_config_under_profile(})})?;- let business_profile = core_utils::validate_and_get_business_profile(- db,- platform.get_processor(),- Some(&profile_id),- )- .await?- .get_required_value("Profile")?;+ let business_profile =+ core_utils::validate_and_get_business_profile(db, &processor, Some(&profile_id))+ .await?+ .get_required_value("Profile")?;utils::when(routing_algorithm.0.algorithm_for != *transaction_type,@@ -568,7 +574,7 @@ pub async fn link_routing_config_under_profile(.update_profile_and_invalidate_routing_config_for_active_algorithm_id_update(db,key_manager_state,- platform.get_processor().get_key_store(),+ processor.get_key_store(),algorithm_id,transaction_type,)@@ -583,7 +589,7 @@ pub async fn link_routing_config_under_profile(#[cfg(feature = "v1")]pub async fn link_routing_config(state: SessionState,- platform: domain::Platform,+ processor: domain::Processor,authentication_profile_id: Option<common_utils::id_type::ProfileId>,algorithm_id: common_utils::id_type::RoutingId,transaction_type: enums::TransactionType,@@ -592,16 +598,16 @@ pub async fn link_routing_config(let db = state.store.as_ref();let routing_algorithm = db- .find_routing_algorithm_by_algorithm_id_merchant_id(+ .find_routing_algorithm_by_algorithm_id_processor_merchant_id(&algorithm_id,- platform.get_processor().get_account().get_id(),+ processor.get_account().get_id(),).await.change_context(errors::ApiErrorResponse::ResourceIdNotFound)?;let business_profile = core_utils::validate_and_get_business_profile(db,- platform.get_processor(),+ &processor,Some(&routing_algorithm.profile_id),).await?@@ -814,7 +820,7 @@ pub async fn link_routing_config(helpers::update_business_profile_active_dynamic_algorithm_ref(db,- platform.get_processor().get_key_store(),+ processor.get_key_store(),business_profile.clone(),dynamic_routing_ref,)@@ -856,7 +862,7 @@ pub async fn link_routing_config(routing_ref.update_algorithm_id(algorithm_id);helpers::update_profile_active_algorithm_ref(db,- platform.get_processor().get_key_store(),+ processor.get_key_store(),business_profile.clone(),routing_ref,&transaction_type,@@ -892,7 +898,7 @@ pub async fn link_routing_config(// redact cgraph cache on rule activationhelpers::redact_cgraph_cache(&state,- platform.get_processor().get_account().get_id(),+ processor.get_account().get_id(),business_profile.get_id(),).await?;@@ -900,7 +906,7 @@ pub async fn link_routing_config(// redact routing cache on rule activationhelpers::redact_routing_cache(&state,- platform.get_processor().get_account().get_id(),+ processor.get_account().get_id(),business_profile.get_id(),).await?;@@ -914,7 +920,7 @@ pub async fn link_routing_config(#[cfg(feature = "v2")]pub async fn retrieve_routing_algorithm_from_algorithm_id(state: SessionState,- platform: domain::Platform,+ processor: domain::Processor,authentication_profile_id: Option<common_utils::id_type::ProfileId>,algorithm_id: common_utils::id_type::RoutingId,) -> RouterResponse<routing_types::MerchantRoutingAlgorithm> {@@ -922,14 +928,14 @@ pub async fn retrieve_routing_algorithm_from_algorithm_id(let db = state.store.as_ref();let routing_algorithm = RoutingAlgorithmUpdate::fetch_routing_algo(- platform.get_processor().get_account().get_id(),+ processor.get_account().get_id(),&algorithm_id,db,).await?;let business_profile = core_utils::validate_and_get_business_profile(db,- platform.get_processor(),+ &processor,Some(&routing_algorithm.0.profile_id),).await?@@ -949,7 +955,7 @@ pub async fn retrieve_routing_algorithm_from_algorithm_id(#[cfg(feature = "v1")]pub async fn retrieve_routing_algorithm_from_algorithm_id(state: SessionState,- platform: domain::Platform,+ processor: domain::Processor,authentication_profile_id: Option<common_utils::id_type::ProfileId>,algorithm_id: common_utils::id_type::RoutingId,) -> RouterResponse<routing_types::MerchantRoutingAlgorithm> {@@ -957,16 +963,16 @@ pub async fn retrieve_routing_algorithm_from_algorithm_id(let db = state.store.as_ref();let routing_algorithm = db- .find_routing_algorithm_by_algorithm_id_merchant_id(+ .find_routing_algorithm_by_algorithm_id_processor_merchant_id(&algorithm_id,- platform.get_processor().get_account().get_id(),+ processor.get_account().get_id(),).await.to_not_found_response(errors::ApiErrorResponse::ResourceIdNotFound)?;let business_profile = core_utils::validate_and_get_business_profile(db,- platform.get_processor(),+ &processor,Some(&routing_algorithm.profile_id),).await?@@ -986,7 +992,7 @@ pub async fn retrieve_routing_algorithm_from_algorithm_id(#[cfg(feature = "v2")]pub async fn unlink_routing_config_under_profile(state: SessionState,- platform: domain::Platform,+ processor: domain::Processor,profile_id: common_utils::id_type::ProfileId,transaction_type: &enums::TransactionType,) -> RouterResponse<routing_types::RoutingDictionaryRecord> {@@ -994,13 +1000,10 @@ pub async fn unlink_routing_config_under_profile(let db = state.store.as_ref();let key_manager_state = &(&state).into();- let business_profile = core_utils::validate_and_get_business_profile(- db,- platform.get_processor(),- Some(&profile_id),- )- .await?- .get_required_value("Profile")?;+ let business_profile =+ core_utils::validate_and_get_business_profile(db, &processor, Some(&profile_id))+ .await?+ .get_required_value("Profile")?;let routing_algo_id = match transaction_type {enums::TransactionType::Payment => business_profile.routing_algorithm_id.clone(),@@ -1012,7 +1015,7 @@ pub async fn unlink_routing_config_under_profile(if let Some(algorithm_id) = routing_algo_id {let record = RoutingAlgorithmUpdate::fetch_routing_algo(- platform.get_processor().get_account().get_id(),+ processor.get_account().get_id(),&algorithm_id,db,)@@ -1022,7 +1025,7 @@ pub async fn unlink_routing_config_under_profile(.update_profile_and_invalidate_routing_config_for_active_algorithm_id_update(db,key_manager_state,- platform.get_processor().get_key_store(),+ processor.get_key_store(),algorithm_id,transaction_type,)@@ -1039,7 +1042,7 @@ pub async fn unlink_routing_config_under_profile(#[cfg(feature = "v1")]pub async fn unlink_routing_config(state: SessionState,- platform: domain::Platform,+ processor: domain::Processor,request: routing_types::RoutingConfigRequest,authentication_profile_id: Option<common_utils::id_type::ProfileId>,transaction_type: enums::TransactionType,@@ -1056,12 +1059,8 @@ pub async fn unlink_routing_config(}).attach_printable("Profile_id not provided")?;- let business_profile = core_utils::validate_and_get_business_profile(- db,- platform.get_processor(),- Some(&profile_id),- )- .await?;+ let business_profile =+ core_utils::validate_and_get_business_profile(db, &processor, Some(&profile_id)).await?;match business_profile {Some(business_profile) => {@@ -1105,7 +1104,7 @@ pub async fn unlink_routing_config(let response = record.foreign_into();helpers::update_profile_active_algorithm_ref(db,- platform.get_processor().get_key_store(),+ processor.get_key_store(),business_profile.clone(),routing_algorithm,&transaction_type,@@ -1115,7 +1114,7 @@ pub async fn unlink_routing_config(// redact cgraph cache on rule activationhelpers::redact_cgraph_cache(&state,- platform.get_processor().get_account().get_id(),+ processor.get_account().get_id(),business_profile.get_id(),).await?;@@ -1123,7 +1122,7 @@ pub async fn unlink_routing_config(// redact routing cache on rule activationhelpers::redact_routing_cache(&state,- platform.get_processor().get_account().get_id(),+ processor.get_account().get_id(),business_profile.get_id(),).await?;@@ -1146,20 +1145,16 @@ pub async fn unlink_routing_config(#[cfg(feature = "v2")]pub async fn update_default_fallback_routing(state: SessionState,- platform: domain::Platform,+ processor: domain::Processor,profile_id: common_utils::id_type::ProfileId,updated_list_of_connectors: Vec<routing_types::RoutableConnectorChoice>,) -> RouterResponse<Vec<routing_types::RoutableConnectorChoice>> {metrics::ROUTING_UPDATE_CONFIG.add(1, &[]);let db = state.store.as_ref();let key_manager_state = &(&state).into();- let profile = core_utils::validate_and_get_business_profile(- db,- platform.get_processor(),- Some(&profile_id),- )- .await?- .get_required_value("Profile")?;+ let profile = core_utils::validate_and_get_business_profile(db, &processor, Some(&profile_id))+ .await?+ .get_required_value("Profile")?;let profile_wrapper = admin::ProfileWrapper::new(profile);let default_list_of_connectors =profile_wrapper.get_default_fallback_list_of_connector_under_profile()?;@@ -1206,7 +1201,7 @@ pub async fn update_default_fallback_routing(db,&updated_list_of_connectors,key_manager_state,- platform.get_processor().get_key_store(),+ processor.get_key_store(),).await?;@@ -1219,7 +1214,7 @@ pub async fn update_default_fallback_routing(#[cfg(feature = "v1")]pub async fn update_default_routing_config(state: SessionState,- platform: domain::Platform,+ processor: domain::Processor,updated_config: Vec<routing_types::RoutableConnectorChoice>,transaction_type: &enums::TransactionType,) -> RouterResponse<Vec<routing_types::RoutableConnectorChoice>> {@@ -1227,11 +1222,7 @@ pub async fn update_default_routing_config(let db = state.store.as_ref();let default_config = helpers::get_merchant_default_config(db,- platform- .get_processor()- .get_account()- .get_id()- .get_string_repr(),+ processor.get_account().get_id().get_string_repr(),transaction_type,).await?;@@ -1263,11 +1254,7 @@ pub async fn update_default_routing_config(helpers::update_merchant_default_config(db,- platform- .get_processor()- .get_account()- .get_id()- .get_string_repr(),+ processor.get_account().get_id().get_string_repr(),updated_config.clone(),transaction_type,)@@ -1280,18 +1267,14 @@ pub async fn update_default_routing_config(#[cfg(feature = "v2")]pub async fn retrieve_default_fallback_algorithm_for_profile(state: SessionState,- platform: domain::Platform,+ processor: domain::Processor,profile_id: common_utils::id_type::ProfileId,) -> RouterResponse<Vec<routing_types::RoutableConnectorChoice>> {metrics::ROUTING_RETRIEVE_DEFAULT_CONFIG.add(1, &[]);let db = state.store.as_ref();- let profile = core_utils::validate_and_get_business_profile(- db,- platform.get_processor(),- Some(&profile_id),- )- .await?- .get_required_value("Profile")?;+ let profile = core_utils::validate_and_get_business_profile(db, &processor, Some(&profile_id))+ .await?+ .get_required_value("Profile")?;let connectors_choice = admin::ProfileWrapper::new(profile).get_default_fallback_list_of_connector_under_profile()?;@@ -1304,7 +1287,7 @@ pub async fn retrieve_default_fallback_algorithm_for_profile(pub async fn retrieve_default_routing_config(state: SessionState,profile_id: Option<common_utils::id_type::ProfileId>,- platform: domain::Platform,+ processor: domain::Processor,transaction_type: &enums::TransactionType,) -> RouterResponse<Vec<routing_types::RoutableConnectorChoice>> {metrics::ROUTING_RETRIEVE_DEFAULT_CONFIG.add(1, &[]);@@ -1312,8 +1295,7 @@ pub async fn retrieve_default_routing_config(let id = profile_id.map(|profile_id| profile_id.get_string_repr().to_owned()).unwrap_or_else(|| {- platform- .get_processor()+ processor.get_account().get_id().get_string_repr()@@ -1331,7 +1313,7 @@ pub async fn retrieve_default_routing_config(#[cfg(feature = "v2")]pub async fn retrieve_routing_config_under_profile(state: SessionState,- platform: domain::Platform,+ processor: domain::Processor,query_params: RoutingRetrieveQuery,profile_id: common_utils::id_type::ProfileId,transaction_type: &enums::TransactionType,@@ -1339,13 +1321,10 @@ pub async fn retrieve_routing_config_under_profile(metrics::ROUTING_RETRIEVE_LINK_CONFIG.add(1, &[]);let db = state.store.as_ref();- let business_profile = core_utils::validate_and_get_business_profile(- db,- platform.get_processor(),- Some(&profile_id),- )- .await?- .get_required_value("Profile")?;+ let business_profile =+ core_utils::validate_and_get_business_profile(db, &processor, Some(&profile_id))+ .await?+ .get_required_value("Profile")?;let record = db.list_routing_algorithm_metadata_by_profile_id(@@ -1545,17 +1524,14 @@ pub async fn retrieve_decision_engine_active_rules(// List all the default fallback algorithms under all the profile under a merchantpub async fn retrieve_default_routing_config_for_profiles(state: SessionState,- platform: domain::Platform,+ processor: domain::Processor,transaction_type: &enums::TransactionType,) -> RouterResponse<Vec<routing_types::ProfileDefaultRoutingConfig>> {metrics::ROUTING_RETRIEVE_CONFIG_FOR_PROFILE.add(1, &[]);let db = state.store.as_ref();let all_profiles = db- .list_profile_by_merchant_id(- platform.get_processor().get_key_store(),- platform.get_processor().get_account().get_id(),- )+ .list_profile_by_merchant_id(processor.get_key_store(), processor.get_account().get_id()).await.to_not_found_response(errors::ApiErrorResponse::ResourceIdNotFound).attach_printable("error retrieving all business profiles for merchant")?;@@ -1593,7 +1569,7 @@ pub async fn retrieve_default_routing_config_for_profiles(pub async fn update_default_routing_config_for_profile(state: SessionState,- platform: domain::Platform,+ processor: domain::Processor,updated_config: Vec<routing_types::RoutableConnectorChoice>,profile_id: common_utils::id_type::ProfileId,transaction_type: &enums::TransactionType,@@ -1602,16 +1578,13 @@ pub async fn update_default_routing_config_for_profile(let db = state.store.as_ref();- let business_profile = core_utils::validate_and_get_business_profile(- db,- platform.get_processor(),- Some(&profile_id),- )- .await?- .get_required_value("Profile")- .change_context(errors::ApiErrorResponse::ProfileNotFound {- id: profile_id.get_string_repr().to_owned(),- })?;+ let business_profile =+ core_utils::validate_and_get_business_profile(db, &processor, Some(&profile_id))+ .await?+ .get_required_value("Profile")+ .change_context(errors::ApiErrorResponse::ProfileNotFound {+ id: profile_id.get_string_repr().to_owned(),+ })?;let default_config = helpers::get_merchant_default_config(db,business_profile.get_id().get_string_repr(),@@ -1673,7 +1646,7 @@ pub async fn update_default_routing_config_for_profile(default_fallback_routing: Some(default_fallback_routing),};db.update_profile_by_profile_id(- platform.get_processor().get_key_store(),+ processor.get_key_store(),business_profile.clone(),profile_update,)@@ -1707,17 +1680,15 @@ pub async fn create_specific_dynamic_routing(),);let db = state.store.as_ref();-- let business_profile: domain::Profile = core_utils::validate_and_get_business_profile(- db,- platform.get_processor(),- Some(&profile_id),- )- .await?- .get_required_value("Profile")- .change_context(errors::ApiErrorResponse::ProfileNotFound {- id: profile_id.get_string_repr().to_owned(),- })?;+ let processor = platform.get_processor();++ let business_profile: domain::Profile =+ core_utils::validate_and_get_business_profile(db, processor, Some(&profile_id))+ .await?+ .get_required_value("Profile")+ .change_context(errors::ApiErrorResponse::ProfileNotFound {+ id: profile_id.get_string_repr().to_owned(),+ })?;let dynamic_routing_algo_ref: routing_types::DynamicRoutingAlgorithmRef = business_profile.dynamic_routing_algorithm@@ -1735,7 +1706,7 @@ pub async fn create_specific_dynamic_routing(| routing::DynamicRoutingFeatures::DynamicConnectorSelection => {Box::pin(helpers::enable_dynamic_routing_algorithm(&state,- platform.get_processor().get_key_store().clone(),+ &platform,business_profile,feature_to_enable,dynamic_routing_algo_ref,@@ -1748,7 +1719,7 @@ pub async fn create_specific_dynamic_routing(// disable specific dynamic routing for the requested profilehelpers::disable_dynamic_routing_algorithm(&state,- platform.get_processor().get_key_store().clone(),+ processor.get_key_store().clone(),business_profile,dynamic_routing_algo_ref,dynamic_routing_type,@@ -1761,7 +1732,7 @@ pub async fn create_specific_dynamic_routing(#[cfg(feature = "v1")]pub async fn configure_dynamic_routing_volume_split(state: SessionState,- platform: domain::Platform,+ processor: domain::Processor,profile_id: common_utils::id_type::ProfileId,routing_info: routing::RoutingVolumeSplit,) -> RouterResponse<routing::RoutingVolumeSplit> {@@ -1780,16 +1751,13 @@ pub async fn configure_dynamic_routing_volume_split(},)?;- let business_profile: domain::Profile = core_utils::validate_and_get_business_profile(- db,- platform.get_processor(),- Some(&profile_id),- )- .await?- .get_required_value("Profile")- .change_context(errors::ApiErrorResponse::ProfileNotFound {- id: profile_id.get_string_repr().to_owned(),- })?;+ let business_profile: domain::Profile =+ core_utils::validate_and_get_business_profile(db, &processor, Some(&profile_id))+ .await?+ .get_required_value("Profile")+ .change_context(errors::ApiErrorResponse::ProfileNotFound {+ id: profile_id.get_string_repr().to_owned(),+ })?;let mut dynamic_routing_algo_ref: routing_types::DynamicRoutingAlgorithmRef = business_profile.dynamic_routing_algorithm@@ -1806,7 +1774,7 @@ pub async fn configure_dynamic_routing_volume_split(helpers::update_business_profile_active_dynamic_algorithm_ref(db,- platform.get_processor().get_key_store(),+ processor.get_key_store(),business_profile.clone(),dynamic_routing_algo_ref.clone(),)@@ -1818,21 +1786,18 @@ pub async fn configure_dynamic_routing_volume_split(#[cfg(feature = "v1")]pub async fn retrieve_dynamic_routing_volume_split(state: SessionState,- platform: domain::Platform,+ processor: domain::Processor,profile_id: common_utils::id_type::ProfileId,) -> RouterResponse<routing_types::RoutingVolumeSplitResponse> {let db = state.store.as_ref();- let business_profile: domain::Profile = core_utils::validate_and_get_business_profile(- db,- platform.get_processor(),- Some(&profile_id),- )- .await?- .get_required_value("Profile")- .change_context(errors::ApiErrorResponse::ProfileNotFound {- id: profile_id.get_string_repr().to_owned(),- })?;+ let business_profile: domain::Profile =+ core_utils::validate_and_get_business_profile(db, &processor, Some(&profile_id))+ .await?+ .get_required_value("Profile")+ .change_context(errors::ApiErrorResponse::ProfileNotFound {+ id: profile_id.get_string_repr().to_owned(),+ })?;let dynamic_routing_algo_ref: routing_types::DynamicRoutingAlgorithmRef = business_profile.dynamic_routing_algorithm@@ -1901,6 +1866,8 @@ pub async fn success_based_routing_update_configs(modified_at: timestamp,algorithm_for: dynamic_routing_algo_to_update.algorithm_for,decision_engine_routing_id: None,+ processor_merchant_id: dynamic_routing_algo_to_update.processor_merchant_id,+ created_by: dynamic_routing_algo_to_update.created_by,};let record = db.insert_routing_algorithm(algo)@@ -2003,6 +1970,8 @@ pub async fn elimination_routing_update_configs(modified_at: timestamp,algorithm_for: dynamic_routing_algo_to_update.algorithm_for,decision_engine_routing_id: None,+ processor_merchant_id: dynamic_routing_algo_to_update.processor_merchant_id,+ created_by: dynamic_routing_algo_to_update.created_by,};let record = db@@ -2067,17 +2036,15 @@ pub async fn contract_based_dynamic_routing_setup(config: Option<routing_types::ContractBasedRoutingConfig>,) -> RouterResult<service_api::ApplicationResponse<routing_types::RoutingDictionaryRecord>> {let db = state.store.as_ref();-- let business_profile: domain::Profile = core_utils::validate_and_get_business_profile(- db,- platform.get_processor(),- Some(&profile_id),- )- .await?- .get_required_value("Profile")- .change_context(errors::ApiErrorResponse::ProfileNotFound {- id: profile_id.get_string_repr().to_owned(),- })?;+ let processor = platform.get_processor();++ let business_profile: domain::Profile =+ core_utils::validate_and_get_business_profile(db, processor, Some(&profile_id))+ .await?+ .get_required_value("Profile")+ .change_context(errors::ApiErrorResponse::ProfileNotFound {+ id: profile_id.get_string_repr().to_owned(),+ })?;let mut dynamic_routing_algo_ref: Option<routing_types::DynamicRoutingAlgorithmRef> =business_profile@@ -2120,7 +2087,7 @@ pub async fn contract_based_dynamic_routing_setup(.attach_printable("Failed to get dynamic_routing_algo_ref")?;return helpers::disable_dynamic_routing_algorithm(&state,- platform.get_processor().get_key_store().clone(),+ processor.get_key_store().clone(),business_profile,algorithm,routing_types::DynamicRoutingType::ContractBasedRouting,@@ -2132,14 +2099,14 @@ pub async fn contract_based_dynamic_routing_setup(.get_required_value("ContractBasedRoutingConfig").attach_printable("Failed to get ContractBasedRoutingConfig from request")?;- let merchant_id = business_profile.merchant_id.clone();+ let processor_merchant_id = processor.get_account().get_id().to_owned();let algorithm_id = common_utils::generate_routing_id_of_default_length();let timestamp = common_utils::date_time::now();let algo = RoutingAlgorithm {algorithm_id: algorithm_id.clone(),profile_id: profile_id.clone(),- merchant_id,+ merchant_id: platform.get_provider().get_account().get_id().to_owned(),name: helpers::CONTRACT_BASED_DYNAMIC_ROUTING_ALGORITHM.to_string(),description: None,kind: diesel_models::enums::RoutingAlgorithmKind::Dynamic,@@ -2148,6 +2115,11 @@ pub async fn contract_based_dynamic_routing_setup(modified_at: timestamp,algorithm_for: common_enums::TransactionType::Payment,decision_engine_routing_id: None,+ processor_merchant_id: Some(processor_merchant_id),+ created_by: platform+ .get_initiator()+ .and_then(|initiator| initiator.to_created_by())+ .map(|created_by| created_by.to_string()),};// 1. if dynamic_routing_algo_ref already present, insert contract based algo and disable success based@@ -2205,9 +2177,9 @@ pub async fn contract_based_dynamic_routing_setup(let label = info.label.clone();let mca = db.find_by_merchant_connector_account_merchant_id_merchant_connector_id(- platform.get_processor().get_account().get_id(),+ processor.get_account().get_id(),&mca_id,- platform.get_processor().get_key_store(),+ processor.get_key_store(),).await.change_context(errors::ApiErrorResponse::MerchantConnectorAccountNotFound {@@ -2237,7 +2209,7 @@ pub async fn contract_based_dynamic_routing_setup(helpers::update_business_profile_active_dynamic_algorithm_ref(db,- platform.get_processor().get_key_store(),+ processor.get_key_store(),business_profile,final_algorithm,)@@ -2256,7 +2228,7 @@ pub async fn contract_based_dynamic_routing_setup(pub async fn contract_based_routing_update_configs(state: SessionState,request: routing_types::ContractBasedRoutingConfig,- platform: domain::Platform,+ processor: domain::Processor,algorithm_id: common_utils::id_type::RoutingId,profile_id: common_utils::id_type::ProfileId,) -> RouterResponse<routing_types::RoutingDictionaryRecord> {@@ -2289,9 +2261,9 @@ pub async fn contract_based_routing_update_configs(for info in info_vec {let mca = db.find_by_merchant_connector_account_merchant_id_merchant_connector_id(- platform.get_processor().get_account().get_id(),+ processor.get_account().get_id(),&info.mca_id,- platform.get_processor().get_key_store(),+ processor.get_key_store(),).await.change_context(errors::ApiErrorResponse::MerchantConnectorAccountNotFound {@@ -2335,6 +2307,8 @@ pub async fn contract_based_routing_update_configs(modified_at: timestamp,algorithm_for: dynamic_routing_algo_to_update.algorithm_for,decision_engine_routing_id: None,+ processor_merchant_id: dynamic_routing_algo_to_update.processor_merchant_id,+ created_by: dynamic_routing_algo_to_update.created_by,};let record = db.insert_routing_algorithm(algo)@@ -2554,7 +2528,7 @@ impl RoutableConnectors {pub async fn migrate_rules_for_profile(state: SessionState,- platform: domain::Platform,+ processor: domain::Processor,query_params: routing_types::RuleMigrationQuery,) -> RouterResult<routing_types::RuleMigrationResult> {use api_models::routing::StaticRoutingAlgorithm as EuclidAlgorithm;@@ -2562,16 +2536,13 @@ pub async fn migrate_rules_for_profile(let profile_id = query_params.profile_id.clone();let db = state.store.as_ref();- let business_profile = core_utils::validate_and_get_business_profile(- db,- platform.get_processor(),- Some(&profile_id),- )- .await?- .get_required_value("Profile")- .change_context(errors::ApiErrorResponse::ProfileNotFound {- id: profile_id.get_string_repr().to_owned(),- })?;+ let business_profile =+ core_utils::validate_and_get_business_profile(db, &processor, Some(&profile_id))+ .await?+ .get_required_value("Profile")+ .change_context(errors::ApiErrorResponse::ProfileNotFound {+ id: profile_id.get_string_repr().to_owned(),+ })?;#[cfg(feature = "v1")]let active_payment_routing_ids: Vec<Option<common_utils::id_type::RoutingId>> = vec![diff --git a/crates/router/src/core/routing/helpers.rs b/crates/router/src/core/routing/helpers.rsindex 59000b1921..42695041c4 100644--- a/crates/router/src/core/routing/helpers.rs+++ b/crates/router/src/core/routing/helpers.rs@@ -1969,7 +1969,7 @@ pub async fn disable_dynamic_routing_algorithm(#[cfg(all(feature = "v1", feature = "dynamic_routing"))]pub async fn enable_dynamic_routing_algorithm(state: &SessionState,- key_store: domain::MerchantKeyStore,+ platform: &domain::Platform,business_profile: domain::Profile,feature_to_enable: routing_types::DynamicRoutingFeatures,dynamic_routing_algo_ref: routing_types::DynamicRoutingAlgorithmRef,@@ -1984,7 +1984,7 @@ pub async fn enable_dynamic_routing_algorithm(Box::pin(enable_specific_routing_algorithm(state,- key_store,+ platform,business_profile,feature_to_enable,dynamic_routing.clone(),@@ -1997,7 +1997,7 @@ pub async fn enable_dynamic_routing_algorithm(routing_types::DynamicRoutingType::EliminationRouting => {Box::pin(enable_specific_routing_algorithm(state,- key_store,+ platform,business_profile,feature_to_enable,dynamic_routing.clone(),@@ -2020,7 +2020,7 @@ pub async fn enable_dynamic_routing_algorithm(#[cfg(all(feature = "v1", feature = "dynamic_routing"))]pub async fn enable_specific_routing_algorithm<A>(state: &SessionState,- key_store: domain::MerchantKeyStore,+ platform: &domain::Platform,business_profile: domain::Profile,feature_to_enable: routing_types::DynamicRoutingFeatures,mut dynamic_routing_algo_ref: routing_types::DynamicRoutingAlgorithmRef,@@ -2035,7 +2035,7 @@ whereif let Some(payload) = payload {return create_specific_dynamic_routing_setup(state,- key_store,+ platform,business_profile,feature_to_enable,dynamic_routing_algo_ref,@@ -2048,7 +2048,7 @@ wherelet Some(mut algo_type) = algo_type else {return default_specific_dynamic_routing_setup(state,- key_store,+ platform,business_profile,feature_to_enable,dynamic_routing_algo_ref,@@ -2065,7 +2065,7 @@ whereelse {return default_specific_dynamic_routing_setup(state,- key_store,+ platform,business_profile,feature_to_enable,dynamic_routing_algo_ref,@@ -2090,7 +2090,7 @@ wheredynamic_routing_algo_ref.update_enabled_features(dynamic_routing_type, feature_to_enable);update_business_profile_active_dynamic_algorithm_ref(db,- &key_store,+ platform.get_processor().get_key_store(),business_profile,dynamic_routing_algo_ref.clone(),)@@ -2112,7 +2112,7 @@ where#[instrument(skip_all)]pub async fn default_specific_dynamic_routing_setup(state: &SessionState,- key_store: domain::MerchantKeyStore,+ platform: &domain::Platform,business_profile: domain::Profile,feature_to_enable: routing_types::DynamicRoutingFeatures,mut dynamic_routing_algo_ref: routing_types::DynamicRoutingAlgorithmRef,@@ -2120,7 +2120,8 @@ pub async fn default_specific_dynamic_routing_setup() -> RouterResult<ApplicationResponse<routing_types::RoutingDictionaryRecord>> {let db = state.store.as_ref();let profile_id = business_profile.get_id().clone();- let merchant_id = business_profile.merchant_id.clone();+ let merchant_id = platform.get_provider().get_account().get_id().to_owned();+ let processor_merchant_id = business_profile.merchant_id.clone();let algorithm_id = common_utils::generate_routing_id_of_default_length();let timestamp = common_utils::date_time::now();@@ -2136,7 +2137,7 @@ pub async fn default_specific_dynamic_routing_setup(routing_algorithm::RoutingAlgorithm {algorithm_id: algorithm_id.clone(),profile_id: profile_id.clone(),- merchant_id,+ merchant_id: merchant_id.clone(),name: SUCCESS_BASED_DYNAMIC_ROUTING_ALGORITHM.to_string(),description: None,kind: diesel_models::enums::RoutingAlgorithmKind::Dynamic,@@ -2145,6 +2146,11 @@ pub async fn default_specific_dynamic_routing_setup(modified_at: timestamp,algorithm_for: common_enums::TransactionType::Payment,decision_engine_routing_id: None,+ processor_merchant_id: Some(processor_merchant_id.clone()),+ created_by: platform+ .get_initiator()+ .and_then(|initiator| initiator.to_created_by())+ .map(|created_by| created_by.to_string()),}}routing_types::DynamicRoutingType::EliminationRouting => {@@ -2167,6 +2173,11 @@ pub async fn default_specific_dynamic_routing_setup(modified_at: timestamp,algorithm_for: common_enums::TransactionType::Payment,decision_engine_routing_id: None,+ processor_merchant_id: Some(processor_merchant_id),+ created_by: platform+ .get_initiator()+ .and_then(|initiator| initiator.to_created_by())+ .map(|created_by| created_by.to_string()),}}@@ -2206,7 +2217,7 @@ pub async fn default_specific_dynamic_routing_setup();update_business_profile_active_dynamic_algorithm_ref(db,- &key_store,+ platform.get_processor().get_key_store(),business_profile,dynamic_routing_algo_ref,)@@ -2225,7 +2236,7 @@ pub async fn default_specific_dynamic_routing_setup(#[instrument(skip_all)]pub async fn create_specific_dynamic_routing_setup(state: &SessionState,- key_store: domain::MerchantKeyStore,+ platform: &domain::Platform,business_profile: domain::Profile,feature_to_enable: routing_types::DynamicRoutingFeatures,mut dynamic_routing_algo_ref: routing_types::DynamicRoutingAlgorithmRef,@@ -2234,7 +2245,8 @@ pub async fn create_specific_dynamic_routing_setup() -> RouterResult<ApplicationResponse<routing_types::RoutingDictionaryRecord>> {let db = state.store.as_ref();let profile_id = business_profile.get_id().clone();- let merchant_id = business_profile.merchant_id.clone();+ let merchant_id = platform.get_provider().get_account().get_id().to_owned();+ let processor_merchant_id = business_profile.merchant_id.clone();let algorithm_id = common_utils::generate_routing_id_of_default_length();let timestamp = common_utils::date_time::now();@@ -2261,7 +2273,7 @@ pub async fn create_specific_dynamic_routing_setup(routing_algorithm::RoutingAlgorithm {algorithm_id: algorithm_id.clone(),profile_id: profile_id.clone(),- merchant_id,+ merchant_id: merchant_id.clone(),name: SUCCESS_BASED_DYNAMIC_ROUTING_ALGORITHM.to_string(),description: None,kind: diesel_models::enums::RoutingAlgorithmKind::Dynamic,@@ -2270,6 +2282,11 @@ pub async fn create_specific_dynamic_routing_setup(modified_at: timestamp,algorithm_for: common_enums::TransactionType::Payment,decision_engine_routing_id: None,+ processor_merchant_id: Some(processor_merchant_id.clone()),+ created_by: platform+ .get_initiator()+ .and_then(|initiator| initiator.to_created_by())+ .map(|created_by| created_by.to_string()),}}routing_types::DynamicRoutingType::EliminationRouting => {@@ -2303,6 +2320,11 @@ pub async fn create_specific_dynamic_routing_setup(modified_at: timestamp,algorithm_for: common_enums::TransactionType::Payment,decision_engine_routing_id: None,+ processor_merchant_id: Some(processor_merchant_id),+ created_by: platform+ .get_initiator()+ .and_then(|initiator| initiator.to_created_by())+ .map(|created_by| created_by.to_string()),}}@@ -2323,7 +2345,7 @@ pub async fn create_specific_dynamic_routing_setup(dynamic_routing_algo_ref.update_feature(feature_to_enable, dynamic_routing_type);update_business_profile_active_dynamic_algorithm_ref(db,- &key_store,+ platform.get_processor().get_key_store(),business_profile,dynamic_routing_algo_ref,)diff --git a/crates/router/src/core/surcharge_decision_config.rs b/crates/router/src/core/surcharge_decision_config.rsindex 352f431107..b057e19475 100644--- a/crates/router/src/core/surcharge_decision_config.rs+++ b/crates/router/src/core/surcharge_decision_config.rs@@ -14,7 +14,7 @@ use crate::{#[cfg(feature = "v1")]pub async fn upsert_surcharge_decision_config(state: SessionState,- platform: domain::Platform,+ processor: domain::Processor,request: SurchargeDecisionConfigReq,) -> RouterResponse<SurchargeDecisionManagerRecord> {use common_utils::ext_traits::{Encode, OptionExt, ValueExt};@@ -36,8 +36,7 @@ pub async fn upsert_surcharge_decision_config(let merchant_surcharge_configs = request.merchant_surcharge_configs;let timestamp = common_utils::date_time::now_unix_timestamp();- let mut algo_id: api_models::routing::RoutingAlgorithmRef = platform- .get_processor()+ let mut algo_id: api_models::routing::RoutingAlgorithmRef = processor.get_account().routing_algorithm.clone()@@ -47,8 +46,7 @@ pub async fn upsert_surcharge_decision_config(.attach_printable("Could not decode the routing algorithm")?.unwrap_or_default();- let key = platform- .get_processor()+ let key = processor.get_account().get_id().get_payment_method_surcharge_routing_id();@@ -59,11 +57,7 @@ pub async fn upsert_surcharge_decision_config(message: "Invalid Request Data".to_string(),}).attach_printable("The Request has an Invalid Comparison")?;- let surcharge_cache_key = platform- .get_processor()- .get_account()- .get_id()- .get_surcharge_dsk_key();+ let surcharge_cache_key = processor.get_account().get_id().get_surcharge_dsk_key();match read_config_key {Ok(config) => {let previous_record: SurchargeDecisionManagerRecord = config@@ -98,7 +92,7 @@ pub async fn upsert_surcharge_decision_config(let config_key = cache::CacheKind::Surcharge(surcharge_cache_key.into());update_merchant_active_algorithm_ref(&state,- platform.get_processor().get_key_store(),+ processor.get_key_store(),config_key,algo_id,)@@ -140,7 +134,7 @@ pub async fn upsert_surcharge_decision_config(let config_key = cache::CacheKind::Surcharge(surcharge_cache_key.into());update_merchant_active_algorithm_ref(&state,- platform.get_processor().get_key_store(),+ processor.get_key_store(),config_key,algo_id,)@@ -159,7 +153,7 @@ pub async fn upsert_surcharge_decision_config(#[cfg(feature = "v2")]pub async fn upsert_surcharge_decision_config(_state: SessionState,- _platform: domain::Platform,+ _processor: domain::Processor,_request: SurchargeDecisionConfigReq,) -> RouterResponse<SurchargeDecisionManagerRecord> {todo!();@@ -168,7 +162,7 @@ pub async fn upsert_surcharge_decision_config(#[cfg(feature = "v1")]pub async fn delete_surcharge_decision_config(state: SessionState,- platform: domain::Platform,+ processor: domain::Processor,) -> RouterResponse<()> {use common_utils::ext_traits::ValueExt;use storage_impl::redis::cache;@@ -176,13 +170,11 @@ pub async fn delete_surcharge_decision_config(use super::routing::helpers::update_merchant_active_algorithm_ref;let db = state.store.as_ref();- let key = platform- .get_processor()+ let key = processor.get_account().get_id().get_payment_method_surcharge_routing_id();- let mut algo_id: api_models::routing::RoutingAlgorithmRef = platform- .get_processor()+ let mut algo_id: api_models::routing::RoutingAlgorithmRef = processor.get_account().routing_algorithm.clone()@@ -192,21 +184,12 @@ pub async fn delete_surcharge_decision_config(.attach_printable("Could not decode the surcharge conditional_config algorithm")?.unwrap_or_default();algo_id.surcharge_config_algo_id = None;- let surcharge_cache_key = platform- .get_processor()- .get_account()- .get_id()- .get_surcharge_dsk_key();+ let surcharge_cache_key = processor.get_account().get_id().get_surcharge_dsk_key();let config_key = cache::CacheKind::Surcharge(surcharge_cache_key.into());- update_merchant_active_algorithm_ref(- &state,- platform.get_processor().get_key_store(),- config_key,- algo_id,- )- .await- .change_context(errors::ApiErrorResponse::InternalServerError)- .attach_printable("Failed to update deleted algorithm ref")?;+ update_merchant_active_algorithm_ref(&state, processor.get_key_store(), config_key, algo_id)+ .await+ .change_context(errors::ApiErrorResponse::InternalServerError)+ .attach_printable("Failed to update deleted algorithm ref")?;db.delete_config_by_key(&key).await@@ -218,18 +201,17 @@ pub async fn delete_surcharge_decision_config(#[cfg(feature = "v2")]pub async fn delete_surcharge_decision_config(_state: SessionState,- _platform: domain::Platform,+ _processor: domain::Processor,) -> RouterResponse<()> {todo!()}pub async fn retrieve_surcharge_decision_config(state: SessionState,- platform: domain::Platform,+ processor: domain::Processor,) -> RouterResponse<SurchargeDecisionManagerResponse> {let db = state.store.as_ref();- let algorithm_id = platform- .get_processor()+ let algorithm_id = processor.get_account().get_id().get_payment_method_surcharge_routing_id();diff --git a/crates/router/src/core/three_ds_decision_rule.rs b/crates/router/src/core/three_ds_decision_rule.rsindex c1f9fc68eb..e669eb7e1b 100644--- a/crates/router/src/core/three_ds_decision_rule.rs+++ b/crates/router/src/core/three_ds_decision_rule.rs@@ -40,13 +40,16 @@ pub async fn execute_three_ds_decision_rule(pub async fn get_three_ds_decision_rule_output(state: &SessionState,- merchant_id: &common_utils::id_type::MerchantId,+ processor_merchant_id: &common_utils::id_type::MerchantId,request: api_models::three_ds_decision_rule::ThreeDsDecisionRuleExecuteRequest,) -> errors::RouterResult<common_types::three_ds_decision_rule_engine::ThreeDSDecision> {let db = state.store.as_ref();// Retrieve the rule from databaselet routing_algorithm = db- .find_routing_algorithm_by_algorithm_id_merchant_id(&request.routing_id, merchant_id)+ .find_routing_algorithm_by_algorithm_id_processor_merchant_id(+ &request.routing_id,+ processor_merchant_id,+ ).await.to_not_found_response(errors::ApiErrorResponse::ResourceIdNotFound)?;let algorithm: Algorithm = routing_algorithmdiff --git a/crates/router/src/db/kafka_store.rs b/crates/router/src/db/kafka_store.rsindex edf0e8e7f7..91183b76b6 100644--- a/crates/router/src/db/kafka_store.rs+++ b/crates/router/src/db/kafka_store.rs@@ -3314,13 +3314,16 @@ impl RoutingAlgorithmInterface for KafkaStore {.await}- async fn find_routing_algorithm_by_algorithm_id_merchant_id(+ async fn find_routing_algorithm_by_algorithm_id_processor_merchant_id(&self,algorithm_id: &id_type::RoutingId,- merchant_id: &id_type::MerchantId,+ processor_merchant_id: &id_type::MerchantId,) -> CustomResult<storage::RoutingAlgorithm, errors::StorageError> {self.diesel_store- .find_routing_algorithm_by_algorithm_id_merchant_id(algorithm_id, merchant_id)+ .find_routing_algorithm_by_algorithm_id_processor_merchant_id(+ algorithm_id,+ processor_merchant_id,+ ).await}diff --git a/crates/router/src/db/routing_algorithm.rs b/crates/router/src/db/routing_algorithm.rsindex 3849b9272e..7b8397dd26 100644--- a/crates/router/src/db/routing_algorithm.rs+++ b/crates/router/src/db/routing_algorithm.rs@@ -1,4 +1,4 @@-use diesel_models::routing_algorithm as routing_storage;+use diesel_models::{errors::DatabaseError, routing_algorithm as routing_storage};use error_stack::report;use router_env::{instrument, tracing};use storage_impl::mock_db::MockDb;@@ -24,10 +24,10 @@ pub trait RoutingAlgorithmInterface {algorithm_id: &common_utils::id_type::RoutingId,) -> StorageResult<routing_storage::RoutingAlgorithm>;- async fn find_routing_algorithm_by_algorithm_id_merchant_id(+ async fn find_routing_algorithm_by_algorithm_id_processor_merchant_id(&self,algorithm_id: &common_utils::id_type::RoutingId,- merchant_id: &common_utils::id_type::MerchantId,+ processor_merchant_id: &common_utils::id_type::MerchantId,) -> StorageResult<routing_storage::RoutingAlgorithm>;async fn find_routing_algorithm_metadata_by_algorithm_id_profile_id(@@ -90,19 +90,37 @@ impl RoutingAlgorithmInterface for Store {}#[instrument(skip_all)]- async fn find_routing_algorithm_by_algorithm_id_merchant_id(+ async fn find_routing_algorithm_by_algorithm_id_processor_merchant_id(&self,algorithm_id: &common_utils::id_type::RoutingId,- merchant_id: &common_utils::id_type::MerchantId,+ processor_merchant_id: &common_utils::id_type::MerchantId,) -> StorageResult<routing_storage::RoutingAlgorithm> {let conn = connection::pg_connection_write(self).await?;- routing_storage::RoutingAlgorithm::find_by_algorithm_id_merchant_id(+ // Stagger release fallback: first try processor_merchant_id, if not found fallback to merchant_id+ // For old records processor_merchant_id is NULL, so we use merchant_id (which has the same value)+ let result = routing_storage::RoutingAlgorithm::find_by_algorithm_id_processor_merchant_id(&conn,algorithm_id,- merchant_id,+ processor_merchant_id,)- .await- .map_err(|error| report!(errors::StorageError::from(error)))+ .await;++ match result {+ Ok(routing_algorithm) => Ok(routing_algorithm),+ Err(error) => {+ if matches!(error.current_context(), DatabaseError::NotFound) {+ routing_storage::RoutingAlgorithm::find_by_algorithm_id_merchant_id(+ &conn,+ algorithm_id,+ processor_merchant_id,+ )+ .await+ .map_err(|error| report!(errors::StorageError::from(error)))+ } else {+ Err(report!(errors::StorageError::from(error)))+ }+ }+ }}#[instrument(skip_all)]@@ -191,10 +209,10 @@ impl RoutingAlgorithmInterface for MockDb {Err(errors::StorageError::MockDbError)?}- async fn find_routing_algorithm_by_algorithm_id_merchant_id(+ async fn find_routing_algorithm_by_algorithm_id_processor_merchant_id(&self,_algorithm_id: &common_utils::id_type::RoutingId,- _merchant_id: &common_utils::id_type::MerchantId,+ _processor_merchant_id: &common_utils::id_type::MerchantId,) -> StorageResult<routing_storage::RoutingAlgorithm> {Err(errors::StorageError::MockDbError)?}diff --git a/crates/router/src/routes/routing.rs b/crates/router/src/routes/routing.rsindex ed47eca33d..66d531b746 100644--- a/crates/router/src/routes/routing.rs+++ b/crates/router/src/routes/routing.rs@@ -59,12 +59,12 @@ pub async fn routing_create_config(},auth::auth_type(&auth::HeaderAuth(auth::ApiKeyAuth {- allow_connected_scope_operation: false,+ allow_connected_scope_operation: true,allow_platform_self_operation: false,}),&auth::JWTAuth {permission: Permission::ProfileRoutingWrite,- allow_connected: false,+ allow_connected: true,allow_platform: false,},req.headers(),@@ -100,12 +100,12 @@ pub async fn routing_create_config(#[cfg(not(feature = "release"))]auth::auth_type(&auth::V2ApiKeyAuth {- allow_connected_scope_operation: false,+ allow_connected_scope_operation: true,allow_platform_self_operation: false,},&auth::JWTAuth {permission: Permission::ProfileRoutingWrite,- allow_connected: false,+ allow_connected: true,allow_platform: false,},req.headers(),@@ -113,7 +113,7 @@ pub async fn routing_create_config(#[cfg(feature = "release")]&auth::JWTAuth {permission: Permission::ProfileRoutingWrite,- allow_connected: false,+ allow_connected: true,allow_platform: false,},api_locking::LockAction::NotApplicable,@@ -140,7 +140,7 @@ pub async fn routing_link_config(let profile_id = auth.profile.map(|profile| profile.get_id().clone());routing::link_routing_config(state,- auth.platform,+ auth.platform.get_processor().clone(),profile_id,algorithm,transaction_type@@ -150,12 +150,12 @@ pub async fn routing_link_config(},auth::auth_type(&auth::HeaderAuth(auth::ApiKeyAuth {- allow_connected_scope_operation: false,+ allow_connected_scope_operation: true,allow_platform_self_operation: false,}),&auth::JWTAuth {permission: Permission::ProfileRoutingWrite,- allow_connected: false,+ allow_connected: true,allow_platform: false,},req.headers(),@@ -188,7 +188,7 @@ pub async fn routing_link_config(|state, auth: auth::AuthenticationData, wrapper, _| {routing::link_routing_config_under_profile(state,- auth.platform,+ auth.platform.get_processor().clone(),wrapper.profile_id,wrapper.algorithm_id.routing_algorithm_id,transaction_type,@@ -197,13 +197,13 @@ pub async fn routing_link_config(#[cfg(not(feature = "release"))]auth::auth_type(&auth::V2ApiKeyAuth {- allow_connected_scope_operation: false,+ allow_connected_scope_operation: true,allow_platform_self_operation: false,},&auth::JWTAuthProfileFromRoute {profile_id: wrapper.profile_id,required_permission: Permission::MerchantRoutingWrite,- allow_connected: false,+ allow_connected: true,allow_platform: false,},req.headers(),@@ -212,7 +212,7 @@ pub async fn routing_link_config(&auth::JWTAuthProfileFromRoute {profile_id: wrapper.profile_id,required_permission: Permission::MerchantRoutingWrite,- allow_connected: false,+ allow_connected: true,allow_platform: false,},api_locking::LockAction::NotApplicable,@@ -238,19 +238,19 @@ pub async fn routing_retrieve_config(let profile_id = auth.profile.map(|profile| profile.get_id().clone());routing::retrieve_routing_algorithm_from_algorithm_id(state,- auth.platform,+ auth.platform.get_processor().clone(),profile_id,algorithm_id,)},auth::auth_type(&auth::HeaderAuth(auth::ApiKeyAuth {- allow_connected_scope_operation: false,+ allow_connected_scope_operation: true,allow_platform_self_operation: false,}),&auth::JWTAuth {permission: Permission::ProfileRoutingRead,- allow_connected: false,+ allow_connected: true,allow_platform: false,},req.headers(),@@ -277,7 +277,7 @@ pub async fn routing_retrieve_config(|state, auth: auth::AuthenticationData, algorithm_id, _| {routing::retrieve_routing_algorithm_from_algorithm_id(state,- auth.platform,+ auth.platform.get_processor().clone(),Some(auth.profile.get_id().clone()),algorithm_id,)@@ -285,12 +285,12 @@ pub async fn routing_retrieve_config(#[cfg(not(feature = "release"))]auth::auth_type(&auth::V2ApiKeyAuth {- allow_connected_scope_operation: false,+ allow_connected_scope_operation: true,allow_platform_self_operation: false,},&auth::JWTAuth {permission: Permission::ProfileRoutingRead,- allow_connected: false,+ allow_connected: true,allow_platform: false,},req.headers(),@@ -298,7 +298,7 @@ pub async fn routing_retrieve_config(#[cfg(feature = "release")]&auth::JWTAuth {permission: Permission::ProfileRoutingRead,- allow_connected: false,+ allow_connected: true,allow_platform: false,},api_locking::LockAction::NotApplicable,@@ -323,7 +323,7 @@ pub async fn list_routing_configs(|state, auth: auth::AuthenticationData, query_params, _| {routing::retrieve_merchant_routing_dictionary(state,- auth.platform,+ auth.platform.clone(),None,query_params.clone(),transaction_type@@ -333,12 +333,12 @@ pub async fn list_routing_configs(},auth::auth_type(&auth::HeaderAuth(auth::ApiKeyAuth {- allow_connected_scope_operation: false,+ allow_connected_scope_operation: true,allow_platform_self_operation: false,}),&auth::JWTAuth {permission: Permission::MerchantRoutingRead,- allow_connected: false,+ allow_connected: true,allow_platform: false,},req.headers(),@@ -365,7 +365,7 @@ pub async fn list_routing_configs_for_profile(|state, auth: auth::AuthenticationData, query_params, _| {routing::retrieve_merchant_routing_dictionary(state,- auth.platform,+ auth.platform.clone(),auth.profile.map(|profile| vec![profile.get_id().clone()]),query_params.clone(),transaction_type@@ -375,7 +375,7 @@ pub async fn list_routing_configs_for_profile(},auth::auth_type(&auth::HeaderAuth(auth::ApiKeyAuth {- allow_connected_scope_operation: false,+ allow_connected_scope_operation: true,allow_platform_self_operation: false,}),&auth::JWTAuth {@@ -408,7 +408,7 @@ pub async fn routing_unlink_config(|state, auth: auth::AuthenticationData, path, _| {routing::unlink_routing_config_under_profile(state,- auth.platform,+ auth.platform.get_processor().clone(),path,transaction_type,)@@ -416,13 +416,13 @@ pub async fn routing_unlink_config(#[cfg(not(feature = "release"))]auth::auth_type(&auth::V2ApiKeyAuth {- allow_connected_scope_operation: false,+ allow_connected_scope_operation: true,allow_platform_self_operation: false,},&auth::JWTAuthProfileFromRoute {profile_id: path,required_permission: Permission::MerchantRoutingWrite,- allow_connected: false,+ allow_connected: true,allow_platform: false,},req.headers(),@@ -431,7 +431,7 @@ pub async fn routing_unlink_config(&auth::JWTAuthProfileFromRoute {profile_id: path,required_permission: Permission::MerchantRoutingWrite,- allow_connected: false,+ allow_connected: true,allow_platform: false,},api_locking::LockAction::NotApplicable,@@ -457,7 +457,7 @@ pub async fn routing_unlink_config(let profile_id = auth.profile.map(|profile| profile.get_id().clone());routing::unlink_routing_config(state,- auth.platform,+ auth.platform.get_processor().clone(),payload_req.clone(),profile_id,transaction_type@@ -467,12 +467,12 @@ pub async fn routing_unlink_config(},auth::auth_type(&auth::HeaderAuth(auth::ApiKeyAuth {- allow_connected_scope_operation: false,+ allow_connected_scope_operation: true,allow_platform_self_operation: false,}),&auth::JWTAuth {permission: Permission::ProfileRoutingWrite,- allow_connected: false,+ allow_connected: true,allow_platform: false,},req.headers(),@@ -502,7 +502,7 @@ pub async fn routing_update_default_config(|state, auth: auth::AuthenticationData, wrapper, _| {routing::update_default_fallback_routing(state,- auth.platform,+ auth.platform.get_processor().clone(),wrapper.profile_id,wrapper.connectors,)@@ -510,12 +510,12 @@ pub async fn routing_update_default_config(#[cfg(not(feature = "release"))]auth::auth_type(&auth::V2ApiKeyAuth {- allow_connected_scope_operation: false,+ allow_connected_scope_operation: true,allow_platform_self_operation: false,},&auth::JWTAuth {permission: Permission::MerchantRoutingWrite,- allow_connected: false,+ allow_connected: true,allow_platform: false,},req.headers(),@@ -523,7 +523,7 @@ pub async fn routing_update_default_config(#[cfg(feature = "release")]&auth::JWTAuth {permission: Permission::MerchantRoutingWrite,- allow_connected: false,+ allow_connected: true,allow_platform: false,},api_locking::LockAction::NotApplicable,@@ -547,19 +547,19 @@ pub async fn routing_update_default_config(|state, auth: auth::AuthenticationData, updated_config, _| {routing::update_default_routing_config(state,- auth.platform,+ auth.platform.get_processor().clone(),updated_config,transaction_type,)},auth::auth_type(&auth::HeaderAuth(auth::ApiKeyAuth {- allow_connected_scope_operation: false,+ allow_connected_scope_operation: true,allow_platform_self_operation: false,}),&auth::JWTAuth {permission: Permission::MerchantRoutingWrite,- allow_connected: false,+ allow_connected: true,allow_platform: false,},req.headers(),@@ -585,20 +585,20 @@ pub async fn routing_retrieve_default_config(|state, auth: auth::AuthenticationData, profile_id, _| {routing::retrieve_default_fallback_algorithm_for_profile(state,- auth.platform,+ auth.platform.get_processor().clone(),profile_id,)},#[cfg(not(feature = "release"))]auth::auth_type(&auth::V2ApiKeyAuth {- allow_connected_scope_operation: false,+ allow_connected_scope_operation: true,allow_platform_self_operation: false,},&auth::JWTAuthProfileFromRoute {profile_id: path,required_permission: Permission::MerchantRoutingRead,- allow_connected: false,+ allow_connected: true,allow_platform: false,},req.headers(),@@ -607,7 +607,7 @@ pub async fn routing_retrieve_default_config(&auth::JWTAuthProfileFromRoute {profile_id: path,required_permission: Permission::MerchantRoutingRead,- allow_connected: false,+ allow_connected: true,allow_platform: false,},api_locking::LockAction::NotApplicable,@@ -632,18 +632,18 @@ pub async fn routing_retrieve_default_config(routing::retrieve_default_routing_config(state,profile_id,- auth.platform,+ auth.platform.get_processor().clone(),transaction_type,)},auth::auth_type(&auth::HeaderAuth(auth::ApiKeyAuth {- allow_connected_scope_operation: false,+ allow_connected_scope_operation: true,allow_platform_self_operation: false,}),&auth::JWTAuth {permission: Permission::ProfileRoutingRead,- allow_connected: false,+ allow_connected: true,allow_platform: false,},req.headers(),@@ -669,19 +669,19 @@ pub async fn upsert_surcharge_decision_manager_config(|state, auth: auth::AuthenticationData, update_decision, _| {surcharge_decision_config::upsert_surcharge_decision_config(state,- auth.platform,+ auth.platform.get_processor().clone(),update_decision,)},#[cfg(not(feature = "release"))]auth::auth_type(&auth::HeaderAuth(auth::ApiKeyAuth {- allow_connected_scope_operation: false,+ allow_connected_scope_operation: true,allow_platform_self_operation: false,}),&auth::JWTAuth {permission: Permission::MerchantSurchargeDecisionManagerWrite,- allow_connected: false,+ allow_connected: true,allow_platform: false,},req.headers(),@@ -689,7 +689,7 @@ pub async fn upsert_surcharge_decision_manager_config(#[cfg(feature = "release")]&auth::JWTAuth {permission: Permission::MerchantSurchargeDecisionManagerWrite,- allow_connected: false,+ allow_connected: true,allow_platform: false,},api_locking::LockAction::NotApplicable,@@ -709,17 +709,20 @@ pub async fn delete_surcharge_decision_manager_config(&req,(),|state, auth: auth::AuthenticationData, (), _| {- surcharge_decision_config::delete_surcharge_decision_config(state, auth.platform)+ surcharge_decision_config::delete_surcharge_decision_config(+ state,+ auth.platform.get_processor().clone(),+ )},#[cfg(not(feature = "release"))]auth::auth_type(&auth::HeaderAuth(auth::ApiKeyAuth {- allow_connected_scope_operation: false,+ allow_connected_scope_operation: true,allow_platform_self_operation: false,}),&auth::JWTAuth {permission: Permission::MerchantSurchargeDecisionManagerWrite,- allow_connected: false,+ allow_connected: true,allow_platform: false,},req.headers(),@@ -727,7 +730,7 @@ pub async fn delete_surcharge_decision_manager_config(#[cfg(feature = "release")]&auth::JWTAuth {permission: Permission::MerchantSurchargeDecisionManagerWrite,- allow_connected: false,+ allow_connected: true,allow_platform: false,},api_locking::LockAction::NotApplicable,@@ -748,12 +751,15 @@ pub async fn retrieve_surcharge_decision_manager_config(&req,(),|state, auth: auth::AuthenticationData, _, _| {- surcharge_decision_config::retrieve_surcharge_decision_config(state, auth.platform)+ surcharge_decision_config::retrieve_surcharge_decision_config(+ state,+ auth.platform.get_processor().clone(),+ )},#[cfg(not(feature = "release"))]auth::auth_type(&auth::HeaderAuth(auth::ApiKeyAuth {- allow_connected_scope_operation: false,+ allow_connected_scope_operation: true,allow_platform_self_operation: false,}),&auth::JWTAuth {@@ -788,17 +794,21 @@ pub async fn upsert_decision_manager_config(&req,json_payload.into_inner(),|state, auth: auth::AuthenticationData, update_decision, _| {- conditional_config::upsert_conditional_config(state, auth.platform, update_decision)+ conditional_config::upsert_conditional_config(+ state,+ auth.platform.get_processor().clone(),+ update_decision,+ )},#[cfg(not(feature = "release"))]auth::auth_type(&auth::HeaderAuth(auth::ApiKeyAuth {- allow_connected_scope_operation: false,+ allow_connected_scope_operation: true,allow_platform_self_operation: false,}),&auth::JWTAuth {permission: Permission::MerchantThreeDsDecisionManagerWrite,- allow_connected: false,+ allow_connected: true,allow_platform: false,},req.headers(),@@ -806,7 +816,7 @@ pub async fn upsert_decision_manager_config(#[cfg(feature = "release")]&auth::JWTAuth {permission: Permission::MerchantThreeDsDecisionManagerWrite,- allow_connected: false,+ allow_connected: true,allow_platform: false,},api_locking::LockAction::NotApplicable,@@ -830,7 +840,11 @@ pub async fn upsert_decision_manager_config(|state, auth: auth::AuthenticationData, update_decision, _| {conditional_config::upsert_conditional_config(state,- auth.platform.get_processor().get_key_store().clone(),+ auth.platform+ .get_processor()+ .clone()+ .get_key_store()+ .clone(),update_decision,auth.profile,)@@ -838,12 +852,12 @@ pub async fn upsert_decision_manager_config(#[cfg(not(feature = "release"))]auth::auth_type(&auth::V2ApiKeyAuth {- allow_connected_scope_operation: false,+ allow_connected_scope_operation: true,allow_platform_self_operation: false,},&auth::JWTAuth {permission: Permission::ProfileThreeDsDecisionManagerWrite,- allow_connected: false,+ allow_connected: true,allow_platform: false,},req.headers(),@@ -851,7 +865,7 @@ pub async fn upsert_decision_manager_config(#[cfg(feature = "release")]&auth::JWTAuth {permission: Permission::ProfileThreeDsDecisionManagerWrite,- allow_connected: false,+ allow_connected: true,allow_platform: false,},api_locking::LockAction::NotApplicable,@@ -872,17 +886,20 @@ pub async fn delete_decision_manager_config(&req,(),|state, auth: auth::AuthenticationData, (), _| {- conditional_config::delete_conditional_config(state, auth.platform)+ conditional_config::delete_conditional_config(+ state,+ auth.platform.get_processor().clone(),+ )},#[cfg(not(feature = "release"))]auth::auth_type(&auth::HeaderAuth(auth::ApiKeyAuth {- allow_connected_scope_operation: false,+ allow_connected_scope_operation: true,allow_platform_self_operation: false,}),&auth::JWTAuth {permission: Permission::MerchantThreeDsDecisionManagerWrite,- allow_connected: false,+ allow_connected: true,allow_platform: false,},req.headers(),@@ -890,7 +907,7 @@ pub async fn delete_decision_manager_config(#[cfg(feature = "release")]&auth::JWTAuth {permission: Permission::MerchantThreeDsDecisionManagerWrite,- allow_connected: false,+ allow_connected: true,allow_platform: false,},api_locking::LockAction::NotApplicable,@@ -914,19 +931,23 @@ pub async fn retrieve_decision_manager_config(|state, auth: auth::AuthenticationData, _, _| {conditional_config::retrieve_conditional_config(state,- auth.platform.get_processor().get_key_store().clone(),+ auth.platform+ .get_processor()+ .clone()+ .get_key_store()+ .clone(),auth.profile,)},#[cfg(not(feature = "release"))]auth::auth_type(&auth::V2ApiKeyAuth {- allow_connected_scope_operation: false,+ allow_connected_scope_operation: true,allow_platform_self_operation: false,},&auth::JWTAuth {permission: Permission::ProfileThreeDsDecisionManagerWrite,- allow_connected: false,+ allow_connected: true,allow_platform: false,},req.headers(),@@ -934,7 +955,7 @@ pub async fn retrieve_decision_manager_config(#[cfg(feature = "release")]&auth::JWTAuth {permission: Permission::ProfileThreeDsDecisionManagerWrite,- allow_connected: false,+ allow_connected: true,allow_platform: false,},api_locking::LockAction::NotApplicable,@@ -956,12 +977,15 @@ pub async fn retrieve_decision_manager_config(&req,(),|state, auth: auth::AuthenticationData, _, _| {- conditional_config::retrieve_conditional_config(state, auth.platform)+ conditional_config::retrieve_conditional_config(+ state,+ auth.platform.get_processor().clone(),+ )},#[cfg(not(feature = "release"))]auth::auth_type(&auth::HeaderAuth(auth::ApiKeyAuth {- allow_connected_scope_operation: false,+ allow_connected_scope_operation: true,allow_platform_self_operation: false,}),&auth::JWTAuth {@@ -1003,7 +1027,7 @@ pub async fn routing_retrieve_linked_config(let profile_id = auth.profile.map(|profile| profile.get_id().clone());routing::retrieve_linked_routing_config(state,- auth.platform,+ auth.platform.clone(),profile_id,query_params,transaction_type@@ -1013,7 +1037,7 @@ pub async fn routing_retrieve_linked_config(},auth::auth_type(&auth::HeaderAuth(auth::ApiKeyAuth {- allow_connected_scope_operation: false,+ allow_connected_scope_operation: true,allow_platform_self_operation: false,}),&auth::JWTAuthProfileFromRoute {@@ -1037,7 +1061,7 @@ pub async fn routing_retrieve_linked_config(let profile_id = auth.profile.map(|profile| profile.get_id().clone());routing::retrieve_linked_routing_config(state,- auth.platform,+ auth.platform.clone(),profile_id,query_params,transaction_type@@ -1047,7 +1071,7 @@ pub async fn routing_retrieve_linked_config(},auth::auth_type(&auth::HeaderAuth(auth::ApiKeyAuth {- allow_connected_scope_operation: false,+ allow_connected_scope_operation: true,allow_platform_self_operation: false,}),&auth::JWTAuth {@@ -1086,7 +1110,7 @@ pub async fn routing_retrieve_linked_config(|state, auth: AuthenticationData, wrapper, _| {routing::retrieve_routing_config_under_profile(state,- auth.platform,+ auth.platform.get_processor().clone(),wrapper.routing_query,wrapper.profile_id,transaction_type,@@ -1095,13 +1119,13 @@ pub async fn routing_retrieve_linked_config(#[cfg(not(feature = "release"))]auth::auth_type(&auth::V2ApiKeyAuth {- allow_connected_scope_operation: false,+ allow_connected_scope_operation: true,allow_platform_self_operation: false,},&auth::JWTAuthProfileFromRoute {profile_id: wrapper.profile_id,required_permission: Permission::ProfileRoutingRead,- allow_connected: false,+ allow_connected: true,allow_platform: false,},req.headers(),@@ -1110,7 +1134,7 @@ pub async fn routing_retrieve_linked_config(&auth::JWTAuthProfileFromRoute {profile_id: wrapper.profile_id,required_permission: Permission::ProfileRoutingRead,- allow_connected: false,+ allow_connected: true,allow_platform: false,},api_locking::LockAction::NotApplicable,@@ -1133,19 +1157,19 @@ pub async fn routing_retrieve_default_config_for_profiles(|state, auth: auth::AuthenticationData, _, _| {routing::retrieve_default_routing_config_for_profiles(state,- auth.platform,+ auth.platform.get_processor().clone(),transaction_type,)},#[cfg(not(feature = "release"))]auth::auth_type(&auth::HeaderAuth(auth::ApiKeyAuth {- allow_connected_scope_operation: false,+ allow_connected_scope_operation: true,allow_platform_self_operation: false,}),&auth::JWTAuth {permission: Permission::MerchantRoutingRead,- allow_connected: false,+ allow_connected: true,allow_platform: false,},req.headers(),@@ -1153,12 +1177,12 @@ pub async fn routing_retrieve_default_config_for_profiles(#[cfg(feature = "release")]auth::auth_type(&auth::HeaderAuth(auth::ApiKeyAuth {- allow_connected_scope_operation: false,+ allow_connected_scope_operation: true,allow_platform_self_operation: false,}),&auth::JWTAuth {permission: Permission::MerchantRoutingRead,- allow_connected: false,+ allow_connected: true,allow_platform: false,},req.headers(),@@ -1189,7 +1213,7 @@ pub async fn routing_update_default_config_for_profile(|state, auth: auth::AuthenticationData, wrapper, _| {routing::update_default_routing_config_for_profile(state,- auth.platform,+ auth.platform.get_processor().clone(),wrapper.updated_config,wrapper.profile_id,transaction_type,@@ -1197,13 +1221,13 @@ pub async fn routing_update_default_config_for_profile(},auth::auth_type(&auth::HeaderAuth(auth::ApiKeyAuth {- allow_connected_scope_operation: false,+ allow_connected_scope_operation: true,allow_platform_self_operation: false,}),&auth::JWTAuthProfileFromRoute {profile_id: routing_payload_wrapper.profile_id,required_permission: Permission::ProfileRoutingWrite,- allow_connected: false,+ allow_connected: true,allow_platform: false,},req.headers(),@@ -1252,13 +1276,13 @@ pub async fn create_success_based_routing(},auth::auth_type(&auth::HeaderAuth(auth::ApiKeyAuth {- allow_connected_scope_operation: false,+ allow_connected_scope_operation: true,allow_platform_self_operation: false,}),&auth::JWTAuthProfileFromRoute {profile_id: wrapper.profile_id,required_permission: Permission::ProfileRoutingWrite,- allow_connected: false,+ allow_connected: true,allow_platform: false,},req.headers(),@@ -1298,13 +1322,13 @@ pub async fn success_based_routing_update_configs(},auth::auth_type(&auth::HeaderAuth(auth::ApiKeyAuth {- allow_connected_scope_operation: false,+ allow_connected_scope_operation: true,allow_platform_self_operation: false,}),&auth::JWTAuthProfileFromRoute {profile_id: routing_payload_wrapper.profile_id,required_permission: Permission::ProfileRoutingWrite,- allow_connected: false,+ allow_connected: true,allow_platform: false,},req.headers(),@@ -1344,13 +1368,13 @@ pub async fn elimination_routing_update_configs(},auth::auth_type(&auth::HeaderAuth(auth::ApiKeyAuth {- allow_connected_scope_operation: false,+ allow_connected_scope_operation: true,allow_platform_self_operation: false,}),&auth::JWTAuthProfileFromRoute {profile_id: routing_payload_wrapper.profile_id,required_permission: Permission::ProfileRoutingWrite,- allow_connected: false,+ allow_connected: true,allow_platform: false,},req.headers(),@@ -1395,11 +1419,11 @@ pub async fn contract_based_routing_setup_config(},auth::auth_type(&auth::HeaderAuth(auth::ApiKeyAuth {- allow_connected_scope_operation: false,+ allow_connected_scope_operation: true,allow_platform_self_operation: false,}),&auth::JWTAuthProfileFromRoute {- allow_connected: false,+ allow_connected: true,allow_platform: false,profile_id: routing_payload_wrapper.profile_id,required_permission: Permission::ProfileRoutingWrite,@@ -1433,11 +1457,11 @@ pub async fn contract_based_routing_update_configs(|state,auth: auth::AuthenticationData,wrapper: routing_types::ContractBasedRoutingPayloadWrapper,- _| async {+ _| async move {Box::pin(routing::contract_based_routing_update_configs(state,wrapper.updated_config,- auth.platform,+ auth.platform.get_processor().clone(),wrapper.algorithm_id,wrapper.profile_id,))@@ -1445,13 +1469,13 @@ pub async fn contract_based_routing_update_configs(},auth::auth_type(&auth::HeaderAuth(auth::ApiKeyAuth {- allow_connected_scope_operation: false,+ allow_connected_scope_operation: true,allow_platform_self_operation: false,}),&auth::JWTAuthProfileFromRoute {profile_id: routing_payload_wrapper.profile_id,required_permission: Permission::ProfileRoutingWrite,- allow_connected: false,+ allow_connected: true,allow_platform: false,},req.headers(),@@ -1500,13 +1524,13 @@ pub async fn create_elimination_routing(},auth::auth_type(&auth::HeaderAuth(auth::ApiKeyAuth {- allow_connected_scope_operation: false,+ allow_connected_scope_operation: true,allow_platform_self_operation: false,}),&auth::JWTAuthProfileFromRoute {profile_id: wrapper.profile_id,required_permission: Permission::ProfileRoutingWrite,- allow_connected: false,+ allow_connected: true,allow_platform: false,},req.headers(),@@ -1545,20 +1569,20 @@ pub async fn set_dynamic_routing_volume_split(_| {routing::configure_dynamic_routing_volume_split(state,- auth.platform,+ auth.platform.get_processor().clone(),payload.profile_id,payload.routing_info,)},auth::auth_type(&auth::HeaderAuth(auth::ApiKeyAuth {- allow_connected_scope_operation: false,+ allow_connected_scope_operation: true,allow_platform_self_operation: false,}),&auth::JWTAuthProfileFromRoute {profile_id: payload.profile_id,required_permission: Permission::ProfileRoutingWrite,- allow_connected: false,+ allow_connected: true,allow_platform: false,},req.headers(),@@ -1584,17 +1608,21 @@ pub async fn get_dynamic_routing_volume_split(&req,payload.clone(),|state, auth: auth::AuthenticationData, payload, _| {- routing::retrieve_dynamic_routing_volume_split(state, auth.platform, payload.profile_id)+ routing::retrieve_dynamic_routing_volume_split(+ state,+ auth.platform.get_processor().clone(),+ payload.profile_id,+ )},auth::auth_type(&auth::HeaderAuth(auth::ApiKeyAuth {- allow_connected_scope_operation: false,+ allow_connected_scope_operation: true,allow_platform_self_operation: false,}),&auth::JWTAuthProfileFromRoute {profile_id: payload.profile_id,required_permission: Permission::ProfileRoutingRead,- allow_connected: false,+ allow_connected: true,allow_platform: false,},req.headers(),@@ -1637,7 +1665,7 @@ pub async fn evaluate_routing_rule(Ok(services::ApplicationResponse::Json(euclid_response))},&auth::ApiKeyAuth {- allow_connected_scope_operation: false,+ allow_connected_scope_operation: true,allow_platform_self_operation: false,},api_locking::LockAction::NotApplicable,@@ -1671,7 +1699,7 @@ pub async fn migrate_routing_rules_for_profile();let res = Box::pin(routing::migrate_rules_for_profile(state,- platform,+ platform.get_processor().clone(),query_params,)).await?;@@ -1722,7 +1750,7 @@ pub async fn call_decide_gateway_open_router(routing::decide_gateway_open_router(state.clone(), payload)},&auth::ApiKeyAuth {- allow_connected_scope_operation: false,+ allow_connected_scope_operation: true,allow_platform_self_operation: false,},api_locking::LockAction::NotApplicable,@@ -1747,7 +1775,7 @@ pub async fn call_update_gateway_score_open_router(routing::update_gateway_score_open_router(state.clone(), payload)},&auth::ApiKeyAuth {- allow_connected_scope_operation: false,+ allow_connected_scope_operation: true,allow_platform_self_operation: false,},api_locking::LockAction::NotApplicable,diff --git a/migrations/2026-05-12-101141_add_processor_merchant_id_created_by_to_routing/down.sql b/migrations/2026-05-12-101141_add_processor_merchant_id_created_by_to_routing/down.sqlnew file mode 100644index 0000000000..fef44d355c--- /dev/null+++ b/migrations/2026-05-12-101141_add_processor_merchant_id_created_by_to_routing/down.sql@@ -0,0 +1,3 @@+-- This file should undo anything in `up.sql`+ALTER TABLE routing_algorithm DROP COLUMN IF EXISTS processor_merchant_id;+ALTER TABLE routing_algorithm DROP COLUMN IF EXISTS created_by;diff --git a/migrations/2026-05-12-101141_add_processor_merchant_id_created_by_to_routing/up.sql b/migrations/2026-05-12-101141_add_processor_merchant_id_created_by_to_routing/up.sqlnew file mode 100644index 0000000000..e576de9bab--- /dev/null+++ b/migrations/2026-05-12-101141_add_processor_merchant_id_created_by_to_routing/up.sql@@ -0,0 +1,5 @@+-- Your SQL goes here+ALTER TABLE routing_algorithm ADD COLUMN IF NOT EXISTS processor_merchant_id VARCHAR(64);+ALTER TABLE routing_algorithm ADD COLUMN IF NOT EXISTS created_by VARCHAR(255);+-- This backfill should be executed after deployment is complete.+UPDATE routing_algorithm SET processor_merchant_id = merchant_id WHERE processor_merchant_id IS NULL;