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(superposition): introduce IncomingWebhookEvent dimension and migrate enum configs to superposition (#11536)
Aniket Burman88d9b1efcfad
diff --git a/config/superposition_seed.toml b/config/superposition_seed.tomlindex 1d29a9c251..b7e83d48be 100644--- a/config/superposition_seed.toml+++ b/config/superposition_seed.toml@@ -46,6 +46,12 @@ schema = { type = "string" }description = "Type of payout retry (single_connector or multi_connector)"change_reason = "Initial setup"+[dimensions.incoming_webhook_events]+position = 7+schema = { type = "string" }+description = "Incoming webhook event type identifier (e.g. payment_intent.succeeded)"+change_reason = "Initial setup"+[default-configs.requires_cvv]value = trueschema = { type = "boolean" }@@ -145,3 +151,21 @@ schema = { type = "boolean" }description = "Whether to return raw payment method details (v2 only)"change_reason = "Initial setup"+[default-configs.routing_result_source]+value = "hyperswitch_routing"+schema = { type = "string", enum = ["decision_engine", "hyperswitch_routing"] }+description = "Source of routing result: decision_engine (external DE) or hyperswitch_routing (inbuilt)"+change_reason = "Initial setup"++[default-configs.threeds_routing_region_uas]+value = "region1"+schema = { type = "string", enum = ["region1", "region2"] }+description = "3DS routing region for UAS (Unified Authentication Service) per organization"+change_reason = "Initial setup"++[default-configs.incoming_webhook_disabled_events]+value = false+schema = { type = "boolean" }+description = "Whether a specific incoming webhook event is disabled for a given connector"+change_reason = "Initial setup"+diff --git a/crates/common_utils/src/id_type/merchant.rs b/crates/common_utils/src/id_type/merchant.rsindex 659f18a3bd..ed3f585378 100644--- a/crates/common_utils/src/id_type/merchant.rs+++ b/crates/common_utils/src/id_type/merchant.rs@@ -170,14 +170,6 @@ impl MerchantId {format!("payment_method_surcharge_id_{}", self.get_string_repr())}- /// get_webhook_config_disabled_events_key- pub fn get_webhook_config_disabled_events_key(&self, connector_id: &str) -> String {- format!(- "whconf_disabled_events_{}_{connector_id}",- self.get_string_repr()- )- }-/// get_should_call_gsm_payout_keypub fn get_should_call_gsm_payout_key(&self,@@ -241,11 +233,6 @@ impl MerchantId {)}- /// Get threeds_routing_region key for merchant- pub fn get_threeds_routing_region_uas_key(&self) -> String {- format!("threeds_routing_region_uas_{}", self.get_string_repr())- }-/// fetch should_return_raw_payment_method_details key for organizationpub fn should_return_raw_payment_method_details_key(&self) -> String {format!(diff --git a/crates/common_utils/src/id_type/organization.rs b/crates/common_utils/src/id_type/organization.rsindex 4f8c58373e..b10d6502da 100644--- a/crates/common_utils/src/id_type/organization.rs+++ b/crates/common_utils/src/id_type/organization.rs@@ -26,11 +26,6 @@ impl OrganizationId {format!("authentication_service_eligible_{}", self.get_string_repr())}- /// fetch Get threeds_routing_region key for organization- pub fn get_threeds_routing_region_uas_key(&self) -> String {- format!("threeds_routing_region_uas_{}", self.get_string_repr())- }-/// Get should call PM modular service key for paymentpub fn get_should_call_pm_modular_service_key(&self) -> String {format!("should_call_pm_modular_service_{}", self.get_string_repr())diff --git a/crates/external_services/src/superposition.rs b/crates/external_services/src/superposition.rsindex 3840488453..15a454052a 100644--- a/crates/external_services/src/superposition.rs+++ b/crates/external_services/src/superposition.rs@@ -430,7 +430,7 @@ pub trait Config {/// Fetch config value from Superposition.fn fetch(superposition_client: &SuperpositionClient,- context: Option<ConfigContext>,+ context: Option<&ConfigContext>,targeting_key: Option<&Self::TargetingKey>,) -> impl std::future::Future<Output = CustomResult<Self::Output, SuperpositionError>> + Sendwhere@@ -441,7 +441,7 @@ pub trait Config {match superposition_client.get_config_value::<Self::Output>(Self::SUPERPOSITION_KEY,- context.as_ref(),+ context,targeting_key_str.as_ref(),).awaitdiff --git a/crates/external_services/src/superposition/types.rs b/crates/external_services/src/superposition/types.rsindex f0605d44e8..e8d5cb7e5e 100644--- a/crates/external_services/src/superposition/types.rs+++ b/crates/external_services/src/superposition/types.rs@@ -186,6 +186,11 @@ impl ConfigContext {self.values.insert(key.to_string(), value.to_string());self}++ /// Get a value from the context by key.+ pub fn get(&self, key: &str) -> Option<&str> {+ self.values.get(key).map(String::as_str)+ }}#[cfg(feature = "superposition")]diff --git a/crates/router/src/consts.rs b/crates/router/src/consts.rsindex 8a78241fbc..4cde3fa48f 100644--- a/crates/router/src/consts.rs+++ b/crates/router/src/consts.rs@@ -391,6 +391,12 @@ pub mod superposition {pub const PAYOUT_TRACKER_MAPPING: &str = "payout_tracker_mapping";/// client session validation enabled configuration keypub const CLIENT_SESSION_VALIDATION_ENABLED: &str = "client_session_validation_enabled";+ /// routing result source configuration key (selects between Hyperswitch and Decision Engine)+ pub const ROUTING_RESULT_SOURCE: &str = "routing_result_source";+ /// 3DS routing region configuration key for UAS+ pub const THREEDS_ROUTING_REGION_UAS: &str = "threeds_routing_region_uas";+ /// disabled webhook events configuration key per merchant and connector+ pub const INCOMING_WEBHOOK_DISABLED_EVENTS: &str = "incoming_webhook_disabled_events";}#[cfg(test)]diff --git a/crates/router/src/core/configs.rs b/crates/router/src/core/configs.rsindex 1b2a1fb8af..480888568f 100644--- a/crates/router/src/core/configs.rs+++ b/crates/router/src/core/configs.rs@@ -7,7 +7,8 @@ pub use dimension_config::{ShouldStoreEligibilityCheckDataForAuthentication,};use error_stack::ResultExt;-use external_services::superposition::{self, ConfigContext};+use external_services::superposition;+pub use external_services::superposition::ConfigContext;use crate::{core::errors::{self, utils::StorageErrorExt, RouterResponse},@@ -173,6 +174,16 @@ pub trait DatabaseBackedConfig: superposition::Config {/// Generate the database key for this config based on dimensionsfn db_key(dimensions: &impl dimension_state::DimensionsBase) -> Option<String>;++ /// Parse the raw database config string into the output type.+ /// Override this for configs whose DB format differs from the Output type+ /// (e.g. a list stored in DB that must be converted to a bool using context).+ fn parse_db_config(config_str: &str, _context: Option<&ConfigContext>) -> Option<Self::Output>+ where+ Self::Output: ConfigType,+ {+ Self::Output::from_config_str(config_str).ok()+ }}/// Fetch configuration value from Superposition with database fallback.@@ -193,7 +204,8 @@ wherelet config_type = C::KEY;let default_value = C::default_value();- let superposition_result = C::fetch(superposition_client, context, targeting_key).await;+ let superposition_result =+ C::fetch(superposition_client, context.as_ref(), targeting_key).await;match superposition_result {Ok(value) => {@@ -212,16 +224,11 @@ whereconfig_type);- let config_result = storage- .find_config_by_key_unwrap_or(- db_key,- Some(default_value.to_config_string().unwrap_or_default()),- )- .await;+ let config_result = storage.find_config_by_key(db_key).await;match config_result.ok()- .and_then(|config| C::Output::from_config_str(&config.config).ok())+ .and_then(|config| C::parse_db_config(&config.config, context.as_ref())){Some(value) => {router_env::logger::info!(@@ -327,3 +334,44 @@ where).await}++/// Fetch dimension-aware string-enum config with String-to-Enum parsing.+/// Used when Config Output is String but caller wants a specific enum type.+pub async fn fetch_db_config_for_string_enum<C, T>(+ storage: &dyn db::StorageInterface,+ superposition_client: &superposition::SuperpositionClient,+ dimensions: &impl dimension_state::DimensionsBase,+ targeting_key: Option<&C::TargetingKey>,+) -> Option<T>+where+ C: DatabaseBackedConfig<Output = String>,+ T: std::str::FromStr,+ open_feature::Client: superposition::GetValue<String>,+{+ let db_key = <C as DatabaseBackedConfig>::db_key(dimensions);+ let context = dimensions.to_superposition_context();++ let raw_value = fetch_db_config::<C>(+ storage,+ superposition_client,+ db_key.as_deref(),+ context,+ targeting_key,+ )+ .await;++ let config_type = C::KEY;+ raw_value+ .parse::<T>()+ .map_err(|_| {+ router_env::logger::error!(+ "Failed to parse string enum for config '{}', using default",+ config_type+ );+ metrics::CONFIG_DEFAULT_FALLBACK.add(+ 1,+ router_env::metric_attributes!(("config_type", config_type)),+ );+ })+ .ok()+}diff --git a/crates/router/src/core/configs/dimension_config.rs b/crates/router/src/core/configs/dimension_config.rsindex 8fb7a654d9..c46d84a480 100644--- a/crates/router/src/core/configs/dimension_config.rs+++ b/crates/router/src/core/configs/dimension_config.rs@@ -1,9 +1,12 @@+use std::collections::HashSet;++use api_models::webhooks::IncomingWebhookEvent;use common_enums;use common_utils::errors::CustomResult;use external_services::superposition;use scheduler::consumer::types::process_data::RetryMapping;-use super::{dimension_state, fetch_db_config_for_dimensions, DatabaseBackedConfig};+use super::{dimension_state, fetch_db_config_for_dimensions, ConfigContext, DatabaseBackedConfig};use crate::{consts::superposition as superposition_consts, db::StorageInterface, utils::id_type};/// This adds `WritableConfig` trait implementation and `set_<key>()` method.///@@ -120,6 +123,44 @@ macro_rules! config {}};+ // String-enum config variant+ (+ superposition_key = $key:ident,+ output = $output:ty,+ default = $default:expr,+ string_enum = true,+ requires = $requirement:ty,+ targeting_key = $targeting_type:ty+ ) => {+ paste::paste! {+ pub struct [<$key:camel>];++ impl superposition::Config for [<$key:camel>] {+ type Output = String;+ type TargetingKey = $targeting_type;+ const SUPERPOSITION_KEY: &'static str = superposition_consts::$key;+ fn default_value() -> Self::Output {+ $default.to_string()+ }+ }++ impl $requirement {+ pub async fn [<get_ $key:lower>](+ &self,+ storage: &dyn StorageInterface,+ superposition_client: &superposition::SuperpositionClient,+ targeting_key: Option<&$targeting_type>,+ ) -> $output {+ crate::core::configs::fetch_db_config_for_string_enum::<[<$key:camel>], $output>(+ storage, superposition_client, self, targeting_key+ )+ .await+ .unwrap_or($default)+ }+ }+ }+ };+// Primitive config variant (no helper function - use get_{{key_name}}() directly on Dimensions)(superposition_key = $key:ident,@@ -463,3 +504,92 @@ impl DatabaseBackedConfig for MaxAutoPayoutRetries {})}}++config! {+ superposition_key = ROUTING_RESULT_SOURCE,+ output = api_models::routing::RoutingResultSource,+ default = api_models::routing::RoutingResultSource::HyperswitchRouting,+ string_enum = true,+ requires = dimension_state::DimensionsWithProcessorAndProviderMerchantIdAndProfileId,+ targeting_key = id_type::ProfileId+}++impl DatabaseBackedConfig for RoutingResultSource {+ const KEY: &'static str = "routing_result_source";+ fn db_key(dimensions: &impl dimension_state::DimensionsBase) -> Option<String> {+ dimensions+ .get_profile_id()+ .map(|id| format!("{}_{}", Self::KEY, id.get_string_repr()))+ }+}++config! {+ superposition_key = THREEDS_ROUTING_REGION_UAS,+ output = common_enums::RoutingRegion,+ default = common_enums::RoutingRegion::Region1,+ string_enum = true,+ requires = dimension_state::DimensionsWithProcessorAndProviderMerchantIdAndOrgId,+ targeting_key = id_type::MerchantId+}++impl DatabaseBackedConfig for ThreedsRoutingRegionUas {+ const KEY: &'static str = "threeds_routing_region_uas";+ fn db_key(dimensions: &impl dimension_state::DimensionsBase) -> Option<String> {+ dimensions+ .get_organization_id()+ .map(|id| format!("{}_{}", Self::KEY, id.get_string_repr()))+ }+}++config! {+ superposition_key = INCOMING_WEBHOOK_DISABLED_EVENTS,+ output = bool,+ default = false,+ requires = dimension_state::DimensionsWithProcessorAndProviderMerchantIdAndConnectorAndWebhookEvent,+ targeting_key = id_type::MerchantId+}++impl DatabaseBackedConfig for IncomingWebhookDisabledEvents {+ const KEY: &'static str = "incoming_webhook_disabled_events";++ fn db_key(dimensions: &impl dimension_state::DimensionsBase) -> Option<String> {+ dimensions+ .get_processor_merchant_id()+ .and_then(|merchant_id| {+ dimensions.get_connector().map(|connector| {+ format!("whconf_{}_{}", merchant_id.get_string_repr(), connector)+ })+ })+ }++ fn parse_db_config(config_str: &str, context: Option<&ConfigContext>) -> Option<Self::Output>+ where+ Self::Output: super::ConfigType,+ {+ let disabled_events: HashSet<IncomingWebhookEvent> = serde_json::from_str(config_str)+ .inspect_err(|err| {+ router_env::logger::error!(+ ?err,+ "Failed to parse incoming_webhook_disabled_events list from db config"+ )+ })+ .ok()?;++ context+ .and_then(|ctx| ctx.get("incoming_webhook_events"))+ .and_then(|event_str| {+ serde_json::from_value::<IncomingWebhookEvent>(serde_json::Value::String(+ event_str.to_string(),+ ))+ .inspect_err(|err| {+ router_env::logger::error!(+ ?err,+ event = %event_str,+ "Failed to parse incoming_webhook_event from context"+ )+ })+ .ok()+ })+ .map(|event| disabled_events.contains(&event))+ }+}diff --git a/crates/router/src/core/configs/dimension_state.rs b/crates/router/src/core/configs/dimension_state.rsindex d76ac04699..565fa3b9bf 100644--- a/crates/router/src/core/configs/dimension_state.rs+++ b/crates/router/src/core/configs/dimension_state.rs@@ -1,5 +1,6 @@use std::marker::PhantomData;+use api_models::webhooks::IncomingWebhookEvent;use common_enums::{connector_enums::Connector, PayoutRetryType};use common_utils::id_type;use external_services::superposition;@@ -67,6 +68,14 @@ pub struct NoPayoutRetryType;#[derive(Clone)]pub struct HasPayoutRetryType;+/// Marker for state WITHOUT incoming_webhook_event+#[derive(Clone)]+pub struct NoWebhookEvent;++/// Marker for state WITH incoming_webhook_event+#[derive(Clone)]+pub struct HasWebhookEvent;+// Dimensional State with type parameters/// Dimensional state with type-level guarantees about which dimensions are present.@@ -80,15 +89,17 @@ pub struct HasPayoutRetryType;/// * `P` - Profile ID: `HasProfileId` or `NoProfileId`/// * `Cn` - Connector: `HasConnector` or `NoConnector`/// * `PRT` - Payout Retry Type: `HasPayoutRetryType` or `NoPayoutRetryType`+/// * `Ev` - Webhook Event type: `HasWebhookEvent` (present) or `NoWebhookEvent` (absent)#[derive(Clone)]-pub struct Dimensions<Pm, M, O, P, Cn, PRT> {+pub struct Dimensions<Pm, M, O, P, Cn, PRT, Ev> {provider_merchant_id: Option<ProviderMerchantId>,processor_merchant_id: Option<ProcessorMerchantId>,organization_id: Option<id_type::OrganizationId>,profile_id: Option<id_type::ProfileId>,connector: Option<Connector>,payout_retry_type: Option<PayoutRetryType>,- _phantom: PhantomData<(Pm, M, O, P, Cn, PRT)>,+ incoming_webhook_event: Option<IncomingWebhookEvent>,+ _phantom: PhantomData<(Pm, M, O, P, Cn, PRT, Ev)>,}impl@@ -99,6 +110,7 @@ implNoProfileId,NoConnector,NoPayoutRetryType,+ NoWebhookEvent,>{pub fn new() -> Self {@@ -109,17 +121,18 @@ implprofile_id: None,connector: None,payout_retry_type: None,+ incoming_webhook_event: None,_phantom: PhantomData,}}}/// Can only add provider_merchant_id if not already present-impl<M, O, P, Cn, PRT> Dimensions<NoProviderMerchantId, M, O, P, Cn, PRT> {+impl<M, O, P, Cn, PRT, Ev> Dimensions<NoProviderMerchantId, M, O, P, Cn, PRT, Ev> {pub fn with_provider_merchant_id(&self,id: ProviderMerchantId,- ) -> Dimensions<HasProviderMerchantId, M, O, P, Cn, PRT> {+ ) -> Dimensions<HasProviderMerchantId, M, O, P, Cn, PRT, Ev> {Dimensions {provider_merchant_id: Some(id),processor_merchant_id: self.processor_merchant_id.clone(),@@ -127,17 +140,18 @@ impl<M, O, P, Cn, PRT> Dimensions<NoProviderMerchantId, M, O, P, Cn, PRT> {profile_id: self.profile_id.clone(),connector: self.connector,payout_retry_type: self.payout_retry_type.clone(),+ incoming_webhook_event: self.incoming_webhook_event,_phantom: PhantomData,}}}/// Can only add processor_merchant_id if not already present-impl<Pm, O, P, Cn, PRT> Dimensions<Pm, NoProcessorMerchantId, O, P, Cn, PRT> {+impl<Pm, O, P, Cn, PRT, Ev> Dimensions<Pm, NoProcessorMerchantId, O, P, Cn, PRT, Ev> {pub fn with_processor_merchant_id(&self,id: ProcessorMerchantId,- ) -> Dimensions<Pm, HasProcessorMerchantId, O, P, Cn, PRT> {+ ) -> Dimensions<Pm, HasProcessorMerchantId, O, P, Cn, PRT, Ev> {Dimensions {provider_merchant_id: self.provider_merchant_id.clone(),processor_merchant_id: Some(id),@@ -145,17 +159,18 @@ impl<Pm, O, P, Cn, PRT> Dimensions<Pm, NoProcessorMerchantId, O, P, Cn, PRT> {profile_id: self.profile_id.clone(),connector: self.connector,payout_retry_type: self.payout_retry_type.clone(),+ incoming_webhook_event: self.incoming_webhook_event,_phantom: PhantomData,}}}/// Can only add organization_id if not already present-impl<Pm, M, P, Cn, PRT> Dimensions<Pm, M, NoOrgId, P, Cn, PRT> {+impl<Pm, M, P, Cn, PRT, Ev> Dimensions<Pm, M, NoOrgId, P, Cn, PRT, Ev> {pub fn with_organization_id(&self,id: id_type::OrganizationId,- ) -> Dimensions<Pm, M, HasOrgId, P, Cn, PRT> {+ ) -> Dimensions<Pm, M, HasOrgId, P, Cn, PRT, Ev> {Dimensions {provider_merchant_id: self.provider_merchant_id.clone(),processor_merchant_id: self.processor_merchant_id.clone(),@@ -163,17 +178,18 @@ impl<Pm, M, P, Cn, PRT> Dimensions<Pm, M, NoOrgId, P, Cn, PRT> {profile_id: self.profile_id.clone(),connector: self.connector,payout_retry_type: self.payout_retry_type.clone(),+ incoming_webhook_event: self.incoming_webhook_event,_phantom: PhantomData,}}}/// Can only add profile_id if not already present-impl<Pm, M, O, Cn, PRT> Dimensions<Pm, M, O, NoProfileId, Cn, PRT> {+impl<Pm, M, O, Cn, PRT, Ev> Dimensions<Pm, M, O, NoProfileId, Cn, PRT, Ev> {pub fn with_profile_id(&self,id: id_type::ProfileId,- ) -> Dimensions<Pm, M, O, HasProfileId, Cn, PRT> {+ ) -> Dimensions<Pm, M, O, HasProfileId, Cn, PRT, Ev> {Dimensions {provider_merchant_id: self.provider_merchant_id.clone(),processor_merchant_id: self.processor_merchant_id.clone(),@@ -181,17 +197,18 @@ impl<Pm, M, O, Cn, PRT> Dimensions<Pm, M, O, NoProfileId, Cn, PRT> {profile_id: Some(id),connector: self.connector,payout_retry_type: self.payout_retry_type.clone(),+ incoming_webhook_event: self.incoming_webhook_event,_phantom: PhantomData,}}}/// Can only add connector if not already present-impl<Pm, M, O, P, PRT> Dimensions<Pm, M, O, P, NoConnector, PRT> {+impl<Pm, M, O, P, PRT, Ev> Dimensions<Pm, M, O, P, NoConnector, PRT, Ev> {pub fn with_connector(&self,connector: Connector,- ) -> Dimensions<Pm, M, O, P, HasConnector, PRT> {+ ) -> Dimensions<Pm, M, O, P, HasConnector, PRT, Ev> {Dimensions {provider_merchant_id: self.provider_merchant_id.clone(),processor_merchant_id: self.processor_merchant_id.clone(),@@ -199,17 +216,18 @@ impl<Pm, M, O, P, PRT> Dimensions<Pm, M, O, P, NoConnector, PRT> {profile_id: self.profile_id.clone(),connector: Some(connector),payout_retry_type: self.payout_retry_type.clone(),+ incoming_webhook_event: self.incoming_webhook_event,_phantom: PhantomData,}}}/// Can only add payout_retry_type if not already present-impl<Pm, M, O, P, Cn> Dimensions<Pm, M, O, P, Cn, NoPayoutRetryType> {+impl<Pm, M, O, P, Cn, Ev> Dimensions<Pm, M, O, P, Cn, NoPayoutRetryType, Ev> {pub fn with_payout_retry_type(&self,retry_type: PayoutRetryType,- ) -> Dimensions<Pm, M, O, P, Cn, HasPayoutRetryType> {+ ) -> Dimensions<Pm, M, O, P, Cn, HasPayoutRetryType, Ev> {Dimensions {provider_merchant_id: self.provider_merchant_id.clone(),processor_merchant_id: self.processor_merchant_id.clone(),@@ -217,16 +235,36 @@ impl<Pm, M, O, P, Cn> Dimensions<Pm, M, O, P, Cn, NoPayoutRetryType> {profile_id: self.profile_id.clone(),connector: self.connector,payout_retry_type: Some(retry_type),+ incoming_webhook_event: self.incoming_webhook_event,+ _phantom: PhantomData,+ }+ }+}++/// Can only add incoming_webhook_event if not already present+impl<Pm, M, O, P, Cn, PRT> Dimensions<Pm, M, O, P, Cn, PRT, NoWebhookEvent> {+ pub fn with_incoming_webhook_event(+ &self,+ event: IncomingWebhookEvent,+ ) -> Dimensions<Pm, M, O, P, Cn, PRT, HasWebhookEvent> {+ Dimensions {+ provider_merchant_id: self.provider_merchant_id.clone(),+ processor_merchant_id: self.processor_merchant_id.clone(),+ organization_id: self.organization_id.clone(),+ profile_id: self.profile_id.clone(),+ connector: self.connector,+ payout_retry_type: self.payout_retry_type.clone(),+ incoming_webhook_event: Some(event),_phantom: PhantomData,}}}/// Can only remove provider_merchant_id if currently present-impl<M, O, P, Cn, PRT> Dimensions<HasProviderMerchantId, M, O, P, Cn, PRT> {+impl<M, O, P, Cn, PRT, Ev> Dimensions<HasProviderMerchantId, M, O, P, Cn, PRT, Ev> {pub fn without_provider_merchant_id(&self,- ) -> Dimensions<NoProviderMerchantId, M, O, P, Cn, PRT> {+ ) -> Dimensions<NoProviderMerchantId, M, O, P, Cn, PRT, Ev> {Dimensions {provider_merchant_id: None,processor_merchant_id: self.processor_merchant_id.clone(),@@ -234,16 +272,17 @@ impl<M, O, P, Cn, PRT> Dimensions<HasProviderMerchantId, M, O, P, Cn, PRT> {profile_id: self.profile_id.clone(),connector: self.connector,payout_retry_type: self.payout_retry_type.clone(),+ incoming_webhook_event: self.incoming_webhook_event,_phantom: PhantomData,}}}/// Can only remove processor_merchant_id if currently present-impl<Pm, O, P, Cn, PRT> Dimensions<Pm, HasProcessorMerchantId, O, P, Cn, PRT> {+impl<Pm, O, P, Cn, PRT, Ev> Dimensions<Pm, HasProcessorMerchantId, O, P, Cn, PRT, Ev> {pub fn without_processor_merchant_id(&self,- ) -> Dimensions<Pm, NoProcessorMerchantId, O, P, Cn, PRT> {+ ) -> Dimensions<Pm, NoProcessorMerchantId, O, P, Cn, PRT, Ev> {Dimensions {provider_merchant_id: self.provider_merchant_id.clone(),processor_merchant_id: None,@@ -251,14 +290,15 @@ impl<Pm, O, P, Cn, PRT> Dimensions<Pm, HasProcessorMerchantId, O, P, Cn, PRT> {profile_id: self.profile_id.clone(),connector: self.connector,payout_retry_type: self.payout_retry_type.clone(),+ incoming_webhook_event: self.incoming_webhook_event,_phantom: PhantomData,}}}/// Can only remove organization_id if currently present-impl<Pm, M, P, Cn, PRT> Dimensions<Pm, M, HasOrgId, P, Cn, PRT> {- pub fn without_organization_id(&self) -> Dimensions<Pm, M, NoOrgId, P, Cn, PRT> {+impl<Pm, M, P, Cn, PRT, Ev> Dimensions<Pm, M, HasOrgId, P, Cn, PRT, Ev> {+ pub fn without_organization_id(&self) -> Dimensions<Pm, M, NoOrgId, P, Cn, PRT, Ev> {Dimensions {provider_merchant_id: self.provider_merchant_id.clone(),processor_merchant_id: self.processor_merchant_id.clone(),@@ -266,14 +306,15 @@ impl<Pm, M, P, Cn, PRT> Dimensions<Pm, M, HasOrgId, P, Cn, PRT> {profile_id: self.profile_id.clone(),connector: self.connector,payout_retry_type: self.payout_retry_type.clone(),+ incoming_webhook_event: self.incoming_webhook_event,_phantom: PhantomData,}}}/// Can only remove profile_id if currently present-impl<Pm, M, O, Cn, PRT> Dimensions<Pm, M, O, HasProfileId, Cn, PRT> {- pub fn without_profile_id(&self) -> Dimensions<Pm, M, O, NoProfileId, Cn, PRT> {+impl<Pm, M, O, Cn, PRT, Ev> Dimensions<Pm, M, O, HasProfileId, Cn, PRT, Ev> {+ pub fn without_profile_id(&self) -> Dimensions<Pm, M, O, NoProfileId, Cn, PRT, Ev> {Dimensions {provider_merchant_id: self.provider_merchant_id.clone(),processor_merchant_id: self.processor_merchant_id.clone(),@@ -281,14 +322,15 @@ impl<Pm, M, O, Cn, PRT> Dimensions<Pm, M, O, HasProfileId, Cn, PRT> {profile_id: None,connector: self.connector,payout_retry_type: self.payout_retry_type.clone(),+ incoming_webhook_event: self.incoming_webhook_event,_phantom: PhantomData,}}}/// Can only remove connector if currently present-impl<Pm, M, O, P, PRT> Dimensions<Pm, M, O, P, HasConnector, PRT> {- pub fn without_connector(&self) -> Dimensions<Pm, M, O, P, NoConnector, PRT> {+impl<Pm, M, O, P, PRT, Ev> Dimensions<Pm, M, O, P, HasConnector, PRT, Ev> {+ pub fn without_connector(&self) -> Dimensions<Pm, M, O, P, NoConnector, PRT, Ev> {Dimensions {provider_merchant_id: self.provider_merchant_id.clone(),processor_merchant_id: self.processor_merchant_id.clone(),@@ -296,13 +338,32 @@ impl<Pm, M, O, P, PRT> Dimensions<Pm, M, O, P, HasConnector, PRT> {profile_id: self.profile_id.clone(),connector: None,payout_retry_type: self.payout_retry_type.clone(),+ incoming_webhook_event: self.incoming_webhook_event,+ _phantom: PhantomData,+ }+ }+}++/// Can only remove incoming_webhook_event if currently present+impl<Pm, M, O, P, Cn, PRT> Dimensions<Pm, M, O, P, Cn, PRT, HasWebhookEvent> {+ pub fn without_incoming_webhook_event(+ &self,+ ) -> Dimensions<Pm, M, O, P, Cn, PRT, NoWebhookEvent> {+ Dimensions {+ provider_merchant_id: self.provider_merchant_id.clone(),+ processor_merchant_id: self.processor_merchant_id.clone(),+ organization_id: self.organization_id.clone(),+ profile_id: self.profile_id.clone(),+ connector: self.connector,+ payout_retry_type: self.payout_retry_type.clone(),+ incoming_webhook_event: None,_phantom: PhantomData,}}}/// provider_merchant_id getter - only available if HasProviderMerchantId-impl<M, O, P, Cn, PRT> Dimensions<HasProviderMerchantId, M, O, P, Cn, PRT> {+impl<M, O, P, Cn, PRT, Ev> Dimensions<HasProviderMerchantId, M, O, P, Cn, PRT, Ev> {pub fn provider_merchant_id(&self) -> Result<&id_type::MerchantId, DimensionError> {self.provider_merchant_id.as_ref()@@ -312,7 +373,7 @@ impl<M, O, P, Cn, PRT> Dimensions<HasProviderMerchantId, M, O, P, Cn, PRT> {}/// processor_merchant_id getter - only available if HasProcessorMerchantId-impl<Pm, O, P, Cn, PRT> Dimensions<Pm, HasProcessorMerchantId, O, P, Cn, PRT> {+impl<Pm, O, P, Cn, PRT, Ev> Dimensions<Pm, HasProcessorMerchantId, O, P, Cn, PRT, Ev> {pub fn processor_merchant_id(&self) -> Result<&id_type::MerchantId, DimensionError> {self.processor_merchant_id.as_ref()@@ -322,7 +383,7 @@ impl<Pm, O, P, Cn, PRT> Dimensions<Pm, HasProcessorMerchantId, O, P, Cn, PRT> {}/// organization_id getter - only available if HasOrgId-impl<Pm, M, P, Cn, PRT> Dimensions<Pm, M, HasOrgId, P, Cn, PRT> {+impl<Pm, M, P, Cn, PRT, Ev> Dimensions<Pm, M, HasOrgId, P, Cn, PRT, Ev> {pub fn organization_id(&self) -> Result<&id_type::OrganizationId, DimensionError> {self.organization_id.as_ref()@@ -331,7 +392,7 @@ impl<Pm, M, P, Cn, PRT> Dimensions<Pm, M, HasOrgId, P, Cn, PRT> {}/// profile_id getter - only available if HasProfileId-impl<Pm, M, O, Cn, PRT> Dimensions<Pm, M, O, HasProfileId, Cn, PRT> {+impl<Pm, M, O, Cn, PRT, Ev> Dimensions<Pm, M, O, HasProfileId, Cn, PRT, Ev> {pub fn profile_id(&self) -> Result<&id_type::ProfileId, DimensionError> {self.profile_id.as_ref()@@ -340,14 +401,14 @@ impl<Pm, M, O, Cn, PRT> Dimensions<Pm, M, O, HasProfileId, Cn, PRT> {}/// connector getter - only available if HasConnector-impl<Pm, M, O, P, PRT> Dimensions<Pm, M, O, P, HasConnector, PRT> {+impl<Pm, M, O, P, PRT, Ev> Dimensions<Pm, M, O, P, HasConnector, PRT, Ev> {pub fn connector(&self) -> Result<Connector, DimensionError> {self.connector.ok_or(DimensionError::MissingConnector)}}// Optional getters (available in any state)-impl<Pm, M, O, P, Cn, PRT> Dimensions<Pm, M, O, P, Cn, PRT> {+impl<Pm, M, O, P, Cn, PRT, Ev> Dimensions<Pm, M, O, P, Cn, PRT, Ev> {pub fn get_provider_merchant_id(&self) -> Option<&id_type::MerchantId> {self.provider_merchant_id.as_ref().map(|id| id.inner())}@@ -371,10 +432,14 @@ impl<Pm, M, O, P, Cn, PRT> Dimensions<Pm, M, O, P, Cn, PRT> {pub fn get_payout_retry_type(&self) -> Option<&PayoutRetryType> {self.payout_retry_type.as_ref()}++ pub fn get_incoming_webhook_event(&self) -> Option<IncomingWebhookEvent> {+ self.incoming_webhook_event+ }}// Superposition context conversion-impl<Pm, M, O, P, Cn, PRT> Dimensions<Pm, M, O, P, Cn, PRT> {+impl<Pm, M, O, P, Cn, PRT, Ev> Dimensions<Pm, M, O, P, Cn, PRT, Ev> {/// Converts dimension state to Superposition config contextpub fn to_superposition_context(&self) -> Option<superposition::ConfigContext> {let mut ctx = superposition::ConfigContext::new();@@ -403,6 +468,12 @@ impl<Pm, M, O, P, Cn, PRT> Dimensions<Pm, M, O, P, Cn, PRT> {ctx = ctx.with("payout_retry_type", prt.to_string().as_str());}+ if let Some(event) = self.incoming_webhook_event {+ if let Ok(serde_json::Value::String(s)) = serde_json::to_value(event) {+ ctx = ctx.with("incoming_webhook_events", s.as_str());+ }+ }+Some(ctx)}}@@ -415,6 +486,7 @@ impl DefaultNoProfileId,NoConnector,NoPayoutRetryType,+ NoWebhookEvent,>{fn default() -> Self {@@ -444,9 +516,12 @@ pub trait DimensionsBase {/// Get payout_retry_type (if available)fn get_payout_retry_type(&self) -> Option<&PayoutRetryType>;++ /// Get incoming_webhook_event (if available)+ fn get_incoming_webhook_event(&self) -> Option<IncomingWebhookEvent>;}-impl<Pm, M, O, P, Cn, PRT> DimensionsBase for Dimensions<Pm, M, O, P, Cn, PRT> {+impl<Pm, M, O, P, Cn, PRT, Ev> DimensionsBase for Dimensions<Pm, M, O, P, Cn, PRT, Ev> {fn to_superposition_context(&self) -> Option<superposition::ConfigContext> {self.to_superposition_context()}@@ -474,6 +549,10 @@ impl<Pm, M, O, P, Cn, PRT> DimensionsBase for Dimensions<Pm, M, O, P, Cn, PRT> {fn get_payout_retry_type(&self) -> Option<&PayoutRetryType> {self.get_payout_retry_type()}++ fn get_incoming_webhook_event(&self) -> Option<IncomingWebhookEvent> {+ self.get_incoming_webhook_event()+ }}// Type aliases@@ -484,6 +563,7 @@ pub type DimensionsWithProviderMerchantId = Dimensions<NoProfileId,NoConnector,NoPayoutRetryType,+ NoWebhookEvent,>;// Type alias - only processor merchant ID present@@ -494,6 +574,7 @@ pub type DimensionsWithProcessorMerchantId = Dimensions<NoProfileId,NoConnector,NoPayoutRetryType,+ NoWebhookEvent,>;// Type aliases - both provider and processor merchant IDs present@@ -504,6 +585,7 @@ pub type DimensionsWithProcessorAndProviderMerchantId = Dimensions<NoProfileId,NoConnector,NoPayoutRetryType,+ NoWebhookEvent,>;pub type DimensionsWithProcessorAndProviderMerchantIdAndProfileId = Dimensions<HasProviderMerchantId,@@ -512,6 +594,7 @@ pub type DimensionsWithProcessorAndProviderMerchantIdAndProfileId = Dimensions<HasProfileId,NoConnector,NoPayoutRetryType,+ NoWebhookEvent,>;pub type DimensionsWithOrgId = Dimensions<NoProviderMerchantId,@@ -520,6 +603,7 @@ pub type DimensionsWithOrgId = Dimensions<NoProfileId,NoConnector,NoPayoutRetryType,+ NoWebhookEvent,>;pub type DimensionsWithProcessorAndProviderMerchantIdAndConnector = Dimensions<HasProviderMerchantId,@@ -528,6 +612,7 @@ pub type DimensionsWithProcessorAndProviderMerchantIdAndConnector = Dimensions<NoProfileId,HasConnector,NoPayoutRetryType,+ NoWebhookEvent,>;pub type DimensionsWithProcessorAndProviderMerchantIdAndProfileIdAndConnector = Dimensions<HasProviderMerchantId,@@ -536,6 +621,7 @@ pub type DimensionsWithProcessorAndProviderMerchantIdAndProfileIdAndConnector =HasProfileId,HasConnector,NoPayoutRetryType,+ NoWebhookEvent,>;pub type DimensionsWithProcessorAndProviderMerchantIdAndOrgId = Dimensions<HasProviderMerchantId,@@ -544,6 +630,7 @@ pub type DimensionsWithProcessorAndProviderMerchantIdAndOrgId = Dimensions<NoProfileId,NoConnector,NoPayoutRetryType,+ NoWebhookEvent,>;pub type DimensionsWithProcessorAndProviderMerchantIdAndOrgIdAndProfileId = Dimensions<HasProviderMerchantId,@@ -552,6 +639,7 @@ pub type DimensionsWithProcessorAndProviderMerchantIdAndOrgIdAndProfileId = DimeHasProfileId,NoConnector,NoPayoutRetryType,+ NoWebhookEvent,>;pub type DimensionsWithProcessorAndProviderMerchantIdAndPayoutRetryType = Dimensions<HasProviderMerchantId,@@ -560,4 +648,14 @@ pub type DimensionsWithProcessorAndProviderMerchantIdAndPayoutRetryType = DimensNoProfileId,NoConnector,HasPayoutRetryType,+ NoWebhookEvent,+>;+pub type DimensionsWithProcessorAndProviderMerchantIdAndConnectorAndWebhookEvent = Dimensions<+ HasProviderMerchantId,+ HasProcessorMerchantId,+ NoOrgId,+ NoProfileId,+ HasConnector,+ NoPayoutRetryType,+ HasWebhookEvent,>;diff --git a/crates/router/src/core/payments.rs b/crates/router/src/core/payments.rsindex e271b338ec..f8d04b6265 100644--- a/crates/router/src/core/payments.rs+++ b/crates/router/src/core/payments.rs@@ -1587,10 +1587,16 @@ where).await?;+ let dimensions = Dimensions::new()+ .with_provider_merchant_id(platform.get_provider().get_provider_merchant_id())+ .with_processor_merchant_id(platform.get_processor().get_processor_merchant_id())+ .with_profile_id(business_profile.get_id().clone());+let connector = set_eligible_connector_for_proxy_in_payment_data(state,&business_profile,platform.get_processor().get_key_store(),+ &dimensions,&mut payment_data,connector_choice,)@@ -9935,6 +9941,7 @@ async fn get_eligible_connector_for_proxy<T: core_routing::GetRoutableConnectorskey_store: &domain::MerchantKeyStore,payment_data: &mut D,connector_choice: T,+ dimensions: &DimensionsWithProcessorAndProviderMerchantIdAndProfileId,business_profile: &domain::Profile,) -> RouterResult<api::ConnectorData>where@@ -9950,7 +9957,7 @@ wherelet proxy_connector_filters = get_proxy_connector_filters(state, recurring_payment_details)?;let eligible_connector_data_list = connector_choice- .get_routable_connectors(state, business_profile, payment_data)+ .get_routable_connectors(state, dimensions, business_profile, payment_data).await?.filter_proxy_flow_supported_connectors(proxy_connector_filters).construct_dsl_and_perform_eligibility_analysis(@@ -10008,6 +10015,7 @@ pub async fn set_eligible_connector_for_proxy_in_payment_data<F, D>(state: &SessionState,business_profile: &domain::Profile,key_store: &domain::MerchantKeyStore,+ dimensions: &DimensionsWithProcessorAndProviderMerchantIdAndProfileId,payment_data: &mut D,connector_choice: api::ConnectorChoice,) -> RouterResult<api::ConnectorData>@@ -10022,6 +10030,7 @@ wherekey_store,payment_data,core_routing::StraightThroughAlgorithmTypeSingle(straight_through),+ dimensions,business_profile,).await?@@ -10032,6 +10041,7 @@ wherekey_store,payment_data,core_routing::DecideConnector,+ dimensions,business_profile,).await?@@ -10466,6 +10476,7 @@ whereasync move {static_dynamic_routing_v1_for_payments(state_ref,+ dimensions,business_profile,txn_data,backend_input,@@ -11349,9 +11360,15 @@ pub async fn route_connector_v2_for_payments(.as_ref().or(business_profile.routing_algorithm_id.as_ref());+ let dimensions = Dimensions::new()+ .with_provider_merchant_id(platform.get_provider().get_provider_merchant_id())+ .with_processor_merchant_id(platform.get_processor().get_processor_merchant_id())+ .with_profile_id(business_profile.get_id().clone());+let (connectors, _) = routing::perform_static_routing_v1(state,platform.get_processor().get_account().get_id(),+ &dimensions,routing_algorithm_id,business_profile,&TransactionData::Payment(transaction_data.clone()),@@ -11391,6 +11408,7 @@ pub async fn route_connector_v2_for_payments(#[allow(clippy::too_many_arguments)]pub async fn static_dynamic_routing_v1_for_payments(state: &SessionState,+ dimensions: &DimensionsWithProcessorAndProviderMerchantIdAndProfileId,business_profile: &domain::Profile,payment_dsl_input: core_routing::PaymentsDslInput<'_>,backend_input: euclid::backend::BackendInput,@@ -11408,6 +11426,7 @@ pub async fn static_dynamic_routing_v1_for_payments(let (connectors, routing_approach) = routing::perform_hybrid_routing_if_enabled(state,business_profile,+ dimensions,&payment_dsl_input,&backend_input,&fallback_config,@@ -11443,6 +11462,7 @@ pub async fn route_connector_v1_for_payouts(pub async fn route_connector_v1_for_payouts(state: &SessionState,processor: &domain::Processor,+ dimensions: &DimensionsWithProcessorAndProviderMerchantIdAndProfileId,business_profile: &domain::Profile,transaction_data: &payouts::PayoutData,routing_data: &mut storage::RoutingData,@@ -11463,6 +11483,7 @@ pub async fn route_connector_v1_for_payouts(let (connectors, _) = routing::perform_static_routing_v1(state,processor.get_account().get_id(),+ dimensions,routing_algorithm_id.as_ref(),business_profile,&TransactionData::Payout(transaction_data),@@ -11532,6 +11553,17 @@ pub async fn payment_external_authentication<F: Clone + Sync>(let db = &*state.store;let key_manager_state = &(&(state)).into();+ let dimensions = Dimensions::new()+ .with_processor_merchant_id(platform.get_processor().get_processor_merchant_id())+ .with_provider_merchant_id(platform.get_provider().get_provider_merchant_id())+ .with_organization_id(+ platform+ .get_processor()+ .get_account()+ .organization_id+ .clone(),+ );+let processor_merchant_id = platform.get_processor().get_account().get_id();let storage_scheme = platform.get_processor().get_account().storage_scheme;let payment_id = req.payment_id;@@ -11706,18 +11738,7 @@ pub async fn payment_external_authentication<F: Clone + Sync>(if helpers::is_merchant_eligible_authentication_service(platform.get_processor(), &state).await?{- let routing_region = uas_utils::fetch_routing_region_for_uas(- &state,- processor_merchant_id.clone(),- platform- .get_processor()- .get_account()- .organization_id- .clone(),- )- .await- .change_context(errors::ApiErrorResponse::InternalServerError)- .attach_printable("Failed to fetch routing path")?;+ let routing_region = uas_utils::fetch_routing_region_for_uas(&state, &dimensions).await;let auth_response =<ExternalAuthentication as UnifiedAuthenticationService>::authentication(&state,diff --git a/crates/router/src/core/payments/operations/payment_confirm.rs b/crates/router/src/core/payments/operations/payment_confirm.rsindex 12ac72307e..bc5fd00889 100644--- a/crates/router/src/core/payments/operations/payment_confirm.rs+++ b/crates/router/src/core/payments/operations/payment_confirm.rs@@ -1728,6 +1728,10 @@ impl<F: Clone + Send + Sync> Domain<F, api::PaymentsRequest, PaymentData<F>> for).await?;let key_manager_state = &(state).into();+ let dimensions = dimension_state::Dimensions::new()+ .with_processor_merchant_id(platform.get_processor().get_processor_merchant_id())+ .with_provider_merchant_id(platform.get_provider().get_provider_merchant_id())+ .with_organization_id(payment_data.payment_attempt.organization_id.clone());if let Some(unified_authentication_service_flow) = unified_authentication_service_flow {match unified_authentication_service_flow {@@ -2012,16 +2016,8 @@ impl<F: Clone + Send + Sync> Domain<F, api::PaymentsRequest, PaymentData<F>> for.change_context(errors::StorageError::DeserializationFailed).attach_printable("Failed to parse customer data from payment intent").change_context(errors::ApiErrorResponse::InternalServerError)?.and_then(|cust| cust.email);--- let routing_region = uas_utils::utils::fetch_routing_region_for_uas(- state,- payment_data.payment_attempt.merchant_id.clone(),- payment_data.payment_attempt.organization_id.clone(),- )- .await- .change_context(errors::ApiErrorResponse::InternalServerError)- .attach_printable("Failed to fetch routing path")?;+ let routing_region =+ uas_utils::utils::fetch_routing_region_for_uas(state, &dimensions).await;let pre_auth_response = uas_utils::types::ExternalAuthentication::pre_authentication(state,@@ -2120,14 +2116,8 @@ impl<F: Clone + Send + Sync> Domain<F, api::PaymentsRequest, PaymentData<F>> for.to_not_found_response(errors::ApiErrorResponse::InternalServerError).attach_printable_lazy(|| format!("Error while fetching authentication record with authentication_id {}", authentication_id.get_string_repr()))?;- let routing_region = uas_utils::utils::fetch_routing_region_for_uas(- state,- payment_data.payment_attempt.merchant_id.clone(),- payment_data.payment_attempt.organization_id.clone(),- )- .await- .change_context(errors::ApiErrorResponse::InternalServerError)- .attach_printable("Failed to fetch routing path")?;+ let routing_region =+ uas_utils::utils::fetch_routing_region_for_uas(state, &dimensions).await;let updated_authentication = if !authentication.authentication_status.is_terminal_status() && is_pull_mechanism_enabled {let post_auth_response = uas_utils::types::ExternalAuthentication::post_authentication(diff --git a/crates/router/src/core/payments/routing.rs b/crates/router/src/core/payments/routing.rsindex 8a59027ca2..8d55978560 100644--- a/crates/router/src/core/payments/routing.rs+++ b/crates/router/src/core/payments/routing.rs@@ -1555,10 +1555,12 @@ impl RoutingStage for HybridRoutingStage {}}+#[allow(clippy::too_many_arguments)]#[cfg(feature = "v1")]pub async fn perform_hybrid_routing_if_enabled(state: &SessionState,business_profile: &domain::Profile,+ dimensions: &dimension_state::DimensionsWithProcessorAndProviderMerchantIdAndProfileId,payment_dsl_input: &routing::PaymentsDslInput<'_>,backend_input: &backend::BackendInput,fallback_config: &[routing_types::RoutableConnectorChoice],@@ -1580,8 +1582,8 @@ pub async fn perform_hybrid_routing_if_enabled(};let is_decision_engine_cutover_enabled = matches!(- utils::get_routing_result_source(state, business_profile).await,- Some(api_models::routing::RoutingResultSource::DecisionEngine)+ utils::get_routing_result_source(state, dimensions).await,+ api_models::routing::RoutingResultSource::DecisionEngine);if is_decision_engine_cutover_enabled {@@ -1647,6 +1649,7 @@ pub async fn static_routing_v1(pub async fn perform_static_routing_v1(state: &SessionState,merchant_id: &common_utils::id_type::MerchantId,+ dimensions: &dimension_state::DimensionsWithProcessorAndProviderMerchantIdAndProfileId,algorithm_id: Option<&common_utils::id_type::RoutingId>,business_profile: &domain::Profile,transaction_data: &routing::TransactionData<'_>,@@ -1772,6 +1775,7 @@ pub async fn perform_static_routing_v1(Ok((utils::select_routing_result(state,+ dimensions,business_profile,routable_connectors,de_evaluated_connector,diff --git a/crates/router/src/core/payments/routing/utils.rs b/crates/router/src/core/payments/routing/utils.rsindex faf3da2603..8479e636a6 100644--- a/crates/router/src/core/payments/routing/utils.rs+++ b/crates/router/src/core/payments/routing/utils.rs@@ -14,10 +14,7 @@ use api_models::{};use async_trait::async_trait;use common_enums::TransactionType;-use common_utils::{- ext_traits::{BytesExt, StringExt},- id_type,-};+use common_utils::{ext_traits::BytesExt, id_type};use diesel_models::{enums, routing_algorithm};use error_stack::ResultExt;use euclid::{@@ -37,7 +34,7 @@ use serde::{Deserialize, Serialize};use super::RoutingResult;use crate::{- core::errors,+ core::{configs::dimension_state, errors},db::domain,routes::{app::SessionStateInfo, SessionState},services::{self, logger},@@ -1731,21 +1728,20 @@ fn stringify_choice(c: RoutableConnectorChoice) -> ConnectorInfo {pub async fn get_routing_result_source(state: &SessionState,- business_profile: &business_profile::Profile,-) -> Option<api_routing::RoutingResultSource> {- state- .store- .find_config_by_key(&format!(- "routing_result_source_{0}",- business_profile.get_id().get_string_repr()- ))+ dimensions: &dimension_state::DimensionsWithProcessorAndProviderMerchantIdAndProfileId,+) -> api_routing::RoutingResultSource {+ // No customer_id and payment_id in call sites so passing Targeting key as None+ dimensions+ .get_routing_result_source(+ state.store.as_ref(),+ state.superposition_service.as_ref(),+ None,+ ).await- .map(|c| c.config.parse_enum("RoutingResultSource").ok())- .unwrap_or(None)}-pub async fn select_routing_result<T>(state: &SessionState,+ dimensions: &dimension_state::DimensionsWithProcessorAndProviderMerchantIdAndProfileId,business_profile: &business_profile::Profile,hyperswitch_result: T,de_result: T,@@ -1753,30 +1749,33 @@ pub async fn select_routing_result<T>(whereT: Clone + IntoIterator,{- let routing_result_source = get_routing_result_source(state, business_profile).await;+ let routing_result_source = get_routing_result_source(state, dimensions).await;- if let Some(api_routing::RoutingResultSource::DecisionEngine) = routing_result_source {- logger::debug!(- business_profile_id=?business_profile.get_id(),- "decision_engine_euclid: Using Decision Engine routing result"- );+ match routing_result_source {+ api_routing::RoutingResultSource::DecisionEngine => {+ logger::debug!(+ business_profile_id=?business_profile.get_id(),+ "decision_engine_euclid: Using Decision Engine routing result"+ );- let is_de_result_empty = de_result.clone().into_iter().next().is_none();- if is_de_result_empty {+ let is_de_result_empty = de_result.clone().into_iter().next().is_none();+ if is_de_result_empty {+ logger::debug!(+ business_profile_id=?business_profile.get_id(),+ "decision_engine_euclid: DE result empty, falling back to Hyperswitch result"+ );+ hyperswitch_result+ } else {+ de_result+ }+ }+ api_routing::RoutingResultSource::HyperswitchRouting => {logger::debug!(business_profile_id=?business_profile.get_id(),- "decision_engine_euclid: DE result empty, falling back to Hyperswitch result"+ "decision_engine_euclid: Using Hyperswitch routing result");hyperswitch_result- } else {- de_result}- } else {- logger::debug!(- business_profile_id=?business_profile.get_id(),- "decision_engine_euclid: Using Hyperswitch routing result"- );- hyperswitch_result}}diff --git a/crates/router/src/core/payouts.rs b/crates/router/src/core/payouts.rsindex 09407d6992..94a159ee73 100644--- a/crates/router/src/core/payouts.rs+++ b/crates/router/src/core/payouts.rs@@ -112,6 +112,7 @@ pub fn get_next_connector(pub async fn get_connector_choice(state: &SessionState,processor: &domain::Processor,+ dimensions: &dimension_state::DimensionsWithProcessorAndProviderMerchantIdAndProfileId,connector: Option<String>,routing_algorithm: Option<serde_json::Value>,payout_data: &mut PayoutData,@@ -149,6 +150,7 @@ pub async fn get_connector_choice(helpers::decide_payout_connector(state,processor,+ dimensions,Some(request_straight_through),&mut routing_data,payout_data,@@ -170,6 +172,7 @@ pub async fn get_connector_choice(helpers::decide_payout_connector(state,processor,+ dimensions,None,&mut routing_data,payout_data,@@ -310,6 +313,7 @@ pub async fn payouts_core(let connector_call_type = get_connector_choice(state,platform.get_processor(),+ &dimensions.with_profile_id(payout_data.business_profile.get_id().clone()),payout_attempt.connector.clone(),routing_algorithm,payout_data,@@ -576,6 +580,10 @@ pub async fn payouts_retrieve_core(&state.locale,)).await?;+ let dimensions = dimension_state::Dimensions::new()+ .with_provider_merchant_id(platform.get_provider().get_provider_merchant_id())+ .with_processor_merchant_id(platform.get_processor().get_processor_merchant_id())+ .with_profile_id(payout_data.business_profile.get_id().clone());let payout_attempt = payout_data.payout_attempt.to_owned();let status = payout_attempt.status;@@ -584,6 +592,7 @@ pub async fn payouts_retrieve_core(let connector_call_type = get_connector_choice(&state,platform.get_processor(),+ &dimensions,payout_attempt.connector.clone(),None,&mut payout_data,diff --git a/crates/router/src/core/payouts/helpers.rs b/crates/router/src/core/payouts/helpers.rsindex 74da1d637b..54e7f8d709 100644--- a/crates/router/src/core/payouts/helpers.rs+++ b/crates/router/src/core/payouts/helpers.rs@@ -271,11 +271,11 @@ impl SourceBankDataOperation {) -> RouterResult<Option<String>> {match source_bank_data {Some(source_bank_data) => {- let sourc_bank_data_token = Self::get_source_bank_data_token();+ let source_bank_data_token = Self::get_source_bank_data_token();let lookup_key = vault::Vault::store_payout_method_data_in_locker(state,- Some(sourc_bank_data_token),+ Some(source_bank_data_token),&api::PayoutMethodData::BankTransfer(source_bank_data),customer_id,merchant_key_store,@@ -1049,6 +1049,7 @@ pub(super) async fn get_or_create_customer_details(pub async fn decide_payout_connector(state: &SessionState,processor: &domain::Processor,+ dimensions: &dimension_state::DimensionsWithProcessorAndProviderMerchantIdAndProfileId,request_straight_through: Option<api::routing::StraightThroughAlgorithm>,routing_data: &mut storage::RoutingData,payout_data: &mut PayoutData,@@ -1183,6 +1184,7 @@ pub async fn decide_payout_connector(route_connector_v1_for_payouts(state,processor,+ dimensions,&payout_data.business_profile,payout_data,routing_data,diff --git a/crates/router/src/core/refunds.rs b/crates/router/src/core/refunds.rsindex 65c7d4e07f..d2bccc1d22 100644--- a/crates/router/src/core/refunds.rs+++ b/crates/router/src/core/refunds.rs@@ -639,10 +639,10 @@ async fn execute_refund_execute_via_direct_with_ucs_shadow(let ucs_state = state.clone();// Capture direct result for comparison (Ok or Err) so the diff is sent in both cases.- let direct_for_compare: Result<types::RefundExecuteRouterData, String> = direct_result- .as_ref()- .map(|rd| rd.clone())- .map_err(|e| format!("{:?}", e));+ let direct_for_compare: Result<types::RefundExecuteRouterData, String> = match &direct_result {+ Ok(rd) => Ok(rd.clone()),+ Err(e) => Err(format!("{:?}", e)),+ };let connector_name = router_data.connector.clone();tokio::spawn(@@ -1196,10 +1196,10 @@ async fn execute_refund_sync_via_direct_with_ucs_shadow(let state = state.clone();let processor = processor.clone();let merchant_connector_account = merchant_connector_account.clone();- let direct_for_compare: Result<types::RefundSyncRouterData, String> = direct_result- .as_ref()- .map(|rd| rd.clone())- .map_err(|e| format!("{:?}", e));+ let direct_for_compare: Result<types::RefundSyncRouterData, String> = match &direct_result {+ Ok(rd) => Ok(rd.clone()),+ Err(e) => Err(format!("{:?}", e)),+ };let connector_name = router_data.connector.clone();tokio::spawn(diff --git a/crates/router/src/core/routing.rs b/crates/router/src/core/routing.rsindex 41092fec37..2a22001c48 100644--- a/crates/router/src/core/routing.rs+++ b/crates/router/src/core/routing.rs@@ -56,6 +56,7 @@ use crate::utils::ValueExt;use crate::{core::admin, db::StorageInterface, utils::ValueExt};use crate::{core::{+ configs::dimension_state,errors::{self, CustomResult, RouterResponse},metrics, utils as core_utils,},@@ -246,9 +247,15 @@ async fn build_list_routing_result(id: profile_id.get_string_repr().to_owned(),})?;+ let dimensions = dimension_state::Dimensions::new()+ .with_provider_merchant_id(platform.get_provider().get_provider_merchant_id())+ .with_processor_merchant_id(platform.get_processor().get_processor_merchant_id())+ .with_profile_id(business_profile.get_id().clone());+list_result.append(&mut select_routing_result(state,+ &dimensions,&business_profile,hs_result_for_profile,de_result_for_profile,@@ -1442,8 +1449,19 @@ pub async fn retrieve_linked_routing_config(hs_records.clone(),"list_active_routing".to_string(),);+ let dimensions = dimension_state::Dimensions::new()+ .with_provider_merchant_id(platform.get_provider().get_provider_merchant_id())+ .with_processor_merchant_id(platform.get_processor().get_processor_merchant_id())+ .with_profile_id(business_profile.get_id().clone());active_algorithms.append(- &mut select_routing_result(&state, &business_profile, hs_records, de_records).await,+ &mut select_routing_result(+ &state,+ &dimensions,+ &business_profile,+ hs_records,+ de_records,+ )+ .await,);}@@ -2373,6 +2391,7 @@ pub trait GetRoutableConnectorsForChoice {async fn get_routable_connectors<F, D>(&self,state: &SessionState,+ dimensions: &dimension_state::DimensionsWithProcessorAndProviderMerchantIdAndProfileId,business_profile: &domain::Profile,payment_data: &mut D,) -> RouterResult<RoutableConnectors>@@ -2388,6 +2407,7 @@ impl GetRoutableConnectorsForChoice for StraightThroughAlgorithmTypeSingle {async fn get_routable_connectors<F, D>(&self,_state: &SessionState,+ _dimensions: &dimension_state::DimensionsWithProcessorAndProviderMerchantIdAndProfileId,_business_profile: &domain::Profile,_payment_data: &mut D,) -> RouterResult<RoutableConnectors>@@ -2426,6 +2446,7 @@ impl GetRoutableConnectorsForChoice for DecideConnector {async fn get_routable_connectors<F, D>(&self,state: &SessionState,+ dimensions: &dimension_state::DimensionsWithProcessorAndProviderMerchantIdAndProfileId,business_profile: &domain::Profile,payment_data: &mut D,) -> RouterResult<RoutableConnectors>@@ -2447,6 +2468,7 @@ impl GetRoutableConnectorsForChoice for DecideConnector {let (connectors, routing_approach) = payments_routing::perform_static_routing_v1(state,&business_profile.merchant_id,+ dimensions,routing_algorithm_id.as_ref(),business_profile,&TransactionData::Payment(transaction_data),diff --git a/crates/router/src/core/unified_authentication_service.rs b/crates/router/src/core/unified_authentication_service.rsindex 4b1ed6df7b..7d4bf4fea4 100644--- a/crates/router/src/core/unified_authentication_service.rs+++ b/crates/router/src/core/unified_authentication_service.rs@@ -1058,6 +1058,11 @@ pub async fn authentication_eligibility_core(let key_manager_state = (&state).into();let merchant_id = merchant_account.get_id();let db = &*state.store;+ let dimensions = dimension_state::Dimensions::new()+ .with_processor_merchant_id(platform.get_processor().get_processor_merchant_id())+ .with_provider_merchant_id(platform.get_provider().get_provider_merchant_id())+ .with_organization_id(merchant_account.organization_id.clone());+let authentication = db.find_authentication_by_merchant_id_authentication_id(merchant_id,@@ -1179,15 +1184,7 @@ pub async fn authentication_eligibility_core(.billing.clone().map(hyperswitch_domain_models::address::Address::from);-- let routing_region = utils::fetch_routing_region_for_uas(- &state,- merchant_id.clone(),- merchant_account.organization_id.clone(),- )- .await- .change_context(ApiErrorResponse::InternalServerError)- .attach_printable("Failed to fetch routing path")?;+ let routing_region = utils::fetch_routing_region_for_uas(&state, &dimensions).await;let pre_auth_response =<ExternalAuthentication as UnifiedAuthenticationService>::pre_authentication(@@ -1290,6 +1287,11 @@ pub async fn authentication_authenticate_core(}).transpose()?;+ let dimensions = dimension_state::Dimensions::new()+ .with_processor_merchant_id(platform.get_processor().get_processor_merchant_id())+ .with_provider_merchant_id(platform.get_provider().get_provider_merchant_id())+ .with_organization_id(merchant_account.organization_id.clone());+let profile_id = authentication.profile_id.clone();let business_profile = db@@ -1335,14 +1337,7 @@ pub async fn authentication_authenticate_core(merchant_connector_account_id_or_connector_name,);- let routing_region = utils::fetch_routing_region_for_uas(- &state,- merchant_id.clone(),- merchant_account.organization_id.clone(),- )- .await- .change_context(ApiErrorResponse::InternalServerError)- .attach_printable("Failed to fetch routing path")?;+ let routing_region = utils::fetch_routing_region_for_uas(&state, &dimensions).await;let auth_response = <ExternalAuthentication as UnifiedAuthenticationService>::authentication(&state,@@ -1792,6 +1787,10 @@ async fn execute_post_authentication_flow(Option<api_models::authentication::AuthenticationVaultTokenData>,Option<api_models::authentication::AuthenticationDetails>,)> {+ let dimensions = dimension_state::Dimensions::new()+ .with_processor_merchant_id(platform.get_processor().get_processor_merchant_id())+ .with_provider_merchant_id(platform.get_provider().get_provider_merchant_id())+ .with_organization_id(merchant_account.organization_id.clone());let post_auth_response = if authentication_connector.is_click_to_pay() {let response = ClickToPay::post_authentication(state,@@ -1809,14 +1808,7 @@ async fn execute_post_authentication_flow(metrics::POST_AUTHENTICATION_CARDS_SUCCESSFULLY_DECRYPTED.add(1, &[]);response} else {- let routing_region = utils::fetch_routing_region_for_uas(- state,- merchant_id.clone(),- merchant_account.organization_id.clone(),- )- .await- .change_context(ApiErrorResponse::InternalServerError)- .attach_printable("Failed to fetch routing path")?;+ let routing_region = utils::fetch_routing_region_for_uas(state, &dimensions).await;ExternalAuthentication::post_authentication(state,business_profile,@@ -2014,10 +2006,16 @@ pub async fn authentication_sync_core(.to_not_found_response(ApiErrorResponse::ProfileNotFound {id: profile_id.get_string_repr().to_owned(),})?;-let dimensions = dimension_state::Dimensions::new()- .with_provider_merchant_id(platform.get_provider().get_provider_merchant_id()).with_processor_merchant_id(platform.get_processor().get_processor_merchant_id())+ .with_provider_merchant_id(platform.get_provider().get_provider_merchant_id())+ .with_organization_id(+ platform+ .get_processor()+ .get_account()+ .organization_id+ .clone(),+ ).with_profile_id(profile_id.clone());let (authentication_connector, three_ds_connector_account) =@@ -2060,13 +2058,8 @@ pub async fn authentication_sync_core(force_3ds_challenge: authentication.force_3ds_challenge,psd2_sca_exemption_type: authentication.psd2_sca_exemption_type,};-- let routing_region = utils::fetch_routing_region_for_uas(- &state,- authentication.merchant_id.clone(),- authentication.organization_id.clone(),- )- .await?;+ let routing_region =+ utils::fetch_routing_region_for_uas(&state, &dimensions.without_profile_id()).await;let authentication_info = Some(AuthenticationInfo {authentication_type: None,@@ -2112,6 +2105,8 @@ pub async fn authentication_sync_core(.await?;}+ let dimensions = dimensions.without_organization_id();+// Determine whether to tokenise or notlet should_disable_vault_tokenization = dimensions.get_should_disable_vault_tokenization(@@ -2292,6 +2287,10 @@ pub async fn authentication_post_sync_core(let merchant_id = merchant_account.get_id();let db = &*state.store;let key_manager_state = (&state).into();+ let dimensions = dimension_state::Dimensions::new()+ .with_processor_merchant_id(platform.get_processor().get_processor_merchant_id())+ .with_provider_merchant_id(platform.get_provider().get_provider_merchant_id())+ .with_organization_id(merchant_account.organization_id.clone());let authentication = db.find_authentication_by_merchant_id_authentication_id(merchant_id,@@ -2324,14 +2323,7 @@ pub async fn authentication_post_sync_core(authentication.authentication_connector.clone(),).await?;- let routing_region = utils::fetch_routing_region_for_uas(- &state,- merchant_id.clone(),- merchant_account.organization_id.clone(),- )- .await- .change_context(ApiErrorResponse::InternalServerError)- .attach_printable("Failed to fetch routing path")?;+ let routing_region = utils::fetch_routing_region_for_uas(&state, &dimensions).await;let post_auth_response =<ExternalAuthentication as UnifiedAuthenticationService>::post_authentication(diff --git a/crates/router/src/core/unified_authentication_service/utils.rs b/crates/router/src/core/unified_authentication_service/utils.rsindex 824b890059..e116912bc0 100644--- a/crates/router/src/core/unified_authentication_service/utils.rs+++ b/crates/router/src/core/unified_authentication_service/utils.rs@@ -1,4 +1,4 @@-use std::{marker::PhantomData, str::FromStr};+use std::marker::PhantomData;#[cfg(feature = "v1")]use api_models::payments::BrowserInformation;@@ -30,6 +30,7 @@ use super::types::{use crate::{consts::DEFAULT_SESSION_EXPIRY,core::{+ configs::dimension_state,errors::{utils::{ConnectorErrorExt, StorageErrorExt},RouterResult,@@ -707,28 +708,13 @@ pub fn construct_uas_webhook_router_data<F: Clone, Req, Res>(pub async fn fetch_routing_region_for_uas(state: &SessionState,- merchant_id: common_utils::id_type::MerchantId,- organization_id: common_utils::id_type::OrganizationId,-) -> RouterResult<RoutingRegion> {- let merchant_path =- fetch_region(state, &merchant_id.get_threeds_routing_region_uas_key()).await;-- Ok(merchant_path- .async_unwrap_or_else(|| async {- fetch_region(state, &organization_id.get_threeds_routing_region_uas_key())- .await- .unwrap_or(RoutingRegion::Region1)- })- .await)-}--async fn fetch_region(state: &SessionState, key: &str) -> Option<RoutingRegion> {- let db = &*state.store;- db.find_config_by_key(key)+ dimensions: &dimension_state::DimensionsWithProcessorAndProviderMerchantIdAndOrgId,+) -> RoutingRegion {+ dimensions+ .get_threeds_routing_region_uas(+ state.store.as_ref(),+ state.superposition_service.as_ref(),+ None,+ ).await- .inspect_err(|err| {- router_env::logger::error!("Failed to fetch region for key as {err}");- })- .ok()- .map(|conf| RoutingRegion::from_str(&conf.config).unwrap_or(RoutingRegion::Region1))}diff --git a/crates/router/src/core/unified_connector_service.rs b/crates/router/src/core/unified_connector_service.rsindex 57698a8ef0..4030642755 100644--- a/crates/router/src/core/unified_connector_service.rs+++ b/crates/router/src/core/unified_connector_service.rs@@ -2817,7 +2817,7 @@ wherelet result = handler(grpc_request, grpc_header).await;let external_latency = start_time.elapsed().as_millis();- let router_result = match result {+ match result {Ok(grpc_response) => {let grpc_response_body = hyperswitch_masking::masked_serialize(&grpc_response).unwrap_or_else(|error| {@@ -2844,9 +2844,7 @@ where);Err(error)}- };-- router_result+ }}// ============================================================================diff --git a/crates/router/src/core/webhooks/gateway.rs b/crates/router/src/core/webhooks/gateway.rsindex b80e975f37..594428aafd 100644--- a/crates/router/src/core/webhooks/gateway.rs+++ b/crates/router/src/core/webhooks/gateway.rs@@ -19,6 +19,7 @@ use crate::core::payments::helpers::MerchantConnectorAccountType;use crate::{consts,core::{+ configs::dimension_state,errors::{self, utils::ConnectorErrorExt, RouterResult},metrics,unified_connector_service::{@@ -132,14 +133,29 @@ pub enum FilterDecision {impl FilterDecision {pub async fn evaluate(event_type: IncomingWebhookEvent, ctx: &WebhookGatewayContext) -> Self {+ use std::str::FromStr;let supported = !matches!(event_type, IncomingWebhookEvent::EventNotSupported);- let enabled = !webhook_utils::is_webhook_event_disabled(- &*ctx.state.store,- &ctx.connector_name,- ctx.platform.get_processor().get_account().get_id(),- &event_type,- )- .await;+ let enabled = {+ match common_enums::connector_enums::Connector::from_str(&ctx.connector_name) {+ Ok(connector_enum) => {+ let dimensions = dimension_state::Dimensions::new()+ .with_processor_merchant_id(+ ctx.platform.get_processor().get_processor_merchant_id(),+ )+ .with_provider_merchant_id(+ ctx.platform.get_provider().get_provider_merchant_id(),+ );+ !webhook_utils::is_webhook_event_disabled(+ &ctx.state,+ connector_enum,+ &dimensions,+ &event_type,+ )+ .await+ }+ Err(_) => false,+ }+ };let flow: api_models::webhooks::WebhookFlow = event_type.into();let return_response = matches!(flow, api_models::webhooks::WebhookFlow::ReturnResponse);diff --git a/crates/router/src/core/webhooks/incoming.rs b/crates/router/src/core/webhooks/incoming.rsindex b2ba95cade..232cd37484 100644--- a/crates/router/src/core/webhooks/incoming.rs+++ b/crates/router/src/core/webhooks/incoming.rs@@ -2805,16 +2805,17 @@ pub async fn process_uas_incoming_webhook<'a>() -> errors::RouterResult<super::gateway::WebhookOutcome> {use hyperswitch_masking::ErasedMaskSerialize;- let routing_region = uas_utils::fetch_routing_region_for_uas(- state,- platform.get_processor().get_account().get_id().clone(),- platform- .get_processor()- .get_account()- .organization_id- .clone(),- )- .await?;+ let dimensions = dimension_state::Dimensions::new()+ .with_processor_merchant_id(platform.get_processor().get_processor_merchant_id())+ .with_provider_merchant_id(platform.get_provider().get_provider_merchant_id())+ .with_organization_id(+ platform+ .get_processor()+ .get_account()+ .organization_id+ .clone(),+ );+ let routing_region = uas_utils::fetch_routing_region_for_uas(state, &dimensions).await;let webhook_data =uas_utils::get_webhook_request_data_for_uas(request_details, Some(routing_region));diff --git a/crates/router/src/core/webhooks/incoming_v2.rs b/crates/router/src/core/webhooks/incoming_v2.rsindex 211fb5480b..06ba942b3c 100644--- a/crates/router/src/core/webhooks/incoming_v2.rs+++ b/crates/router/src/core/webhooks/incoming_v2.rs@@ -20,6 +20,7 @@ use crate::core::webhooks::recovery_incoming;use crate::{core::{api_locking,+ configs::dimension_state,errors::{self, ConnectorErrorExt, CustomResult, RouterResponse, StorageErrorExt},metrics,payments::{@@ -61,6 +62,10 @@ pub async fn incoming_webhooks_wrapper<W: types::OutgoingWebhookType>(body: actix_web::web::Bytes,is_relay_webhook: bool,) -> RouterResponse<serde_json::Value> {+ let dimensions = dimension_state::Dimensions::new()+ .with_provider_merchant_id(platform.get_provider().get_provider_merchant_id())+ .with_processor_merchant_id(platform.get_processor().get_processor_merchant_id());+let start_instant = Instant::now();let (application_response, webhooks_response_tracker, serialized_req) =Box::pin(incoming_webhooks_core::<W>(@@ -144,6 +149,10 @@ async fn incoming_webhooks_core<W: types::OutgoingWebhookType>(platform.get_processor().get_account().get_id().clone())),);+ let dimensions = dimension_state::Dimensions::new()+ .with_provider_merchant_id(platform.get_provider().get_provider_merchant_id())+ .with_processor_merchant_id(platform.get_processor().get_processor_merchant_id());+let mut request_details = IncomingWebhookRequestDetails {method: req.method().clone(),uri: req.uri().clone(),@@ -155,12 +164,13 @@ async fn incoming_webhooks_core<W: types::OutgoingWebhookType>(// Fetch the merchant connector account to get the webhooks source secret// `webhooks source secret` is a secret shared between the merchant and connector// This is used for source verification and webhooks integrity- let (merchant_connector_account, connector, connector_name) = fetch_mca_and_connector(- &state,- connector_id,- platform.get_processor().get_key_store(),- )- .await?;+ let (merchant_connector_account, connector, connector_enum, connector_name) =+ fetch_mca_and_connector(+ &state,+ connector_id,+ platform.get_processor().get_key_store(),+ )+ .await?;let decoded_body = connector.decode_webhook_body(@@ -239,13 +249,8 @@ async fn incoming_webhooks_core<W: types::OutgoingWebhookType>(event_type,webhooks::IncomingWebhookEvent::EventNotSupported);- let is_webhook_event_enabled = !utils::is_webhook_event_disabled(- &*state.clone().store,- connector_name.as_str(),- platform.get_processor().get_account().get_id(),- &event_type,- )- .await;+ let is_webhook_event_enabled =+ !utils::is_webhook_event_disabled(&state, connector_enum, &dimensions, &event_type).await;//process webhook further only if webhook event is enabled and is not event_not_supportedlet process_webhook_further = is_webhook_event_enabled && is_webhook_event_supported;@@ -262,13 +267,6 @@ async fn incoming_webhooks_core<W: types::OutgoingWebhookType>(.get_webhook_object_reference_id(&request_details).switch().attach_printable("Could not find object reference id in incoming webhook body")?;- let connector_enum = api_models::enums::Connector::from_str(&connector_name)- .change_context(errors::ApiErrorResponse::InvalidDataValue {- field_name: "connector",- })- .attach_printable_lazy(|| {- format!("unable to parse connector name {connector_name:?}")- })?;let connectors_with_source_verification_call = &state.conf.webhook_source_verification_call;let source_verified = if connectors_with_source_verification_call@@ -812,8 +810,15 @@ async fn fetch_mca_and_connector(state: &SessionState,connector_id: &common_utils::id_type::MerchantConnectorAccountId,key_store: &domain::MerchantKeyStore,-) -> CustomResult<(domain::MerchantConnectorAccount, ConnectorEnum, String), errors::ApiErrorResponse>-{+) -> CustomResult<+ (+ domain::MerchantConnectorAccount,+ ConnectorEnum,+ common_enums::connector_enums::Connector,+ String,+ ),+ errors::ApiErrorResponse,+> {let db = &state.store;let mca = db.find_merchant_connector_account_by_id(connector_id, key_store)@@ -823,11 +828,9 @@ async fn fetch_mca_and_connector(}).attach_printable("error while fetching merchant_connector_account from connector_id")?;- let (connector, connector_name) = get_connector_by_connector_name(- state,- &mca.connector_name.to_string(),- Some(mca.get_id()),- )?;+ let connector_enum = mca.connector_name;+ let (connector, connector_name) =+ get_connector_by_connector_name(state, &connector_enum.to_string(), Some(mca.get_id()))?;- Ok((mca, connector, connector_name))+ Ok((mca, connector, connector_enum, connector_name))}diff --git a/crates/router/src/core/webhooks/utils.rs b/crates/router/src/core/webhooks/utils.rsindex 1056343ee6..5571af511a 100644--- a/crates/router/src/core/webhooks/utils.rs+++ b/crates/router/src/core/webhooks/utils.rs@@ -19,11 +19,11 @@ use router_env::tracing;use super::MERCHANT_ID;use crate::{core::{+ configs::dimension_state,errors::{self},metrics,payments::{self, helpers},},- db::{get_and_deserialize_key, StorageInterface},errors::RouterResult,routes::app::SessionStateInfo,services::{self, connector_integration_interface::ConnectorEnum, logger},@@ -41,41 +41,24 @@ const IRRELEVANT_CONNECTOR_REQUEST_REFERENCE_ID_IN_SOURCE_VERIFICATION_FLOW: &st"irrelevant_connector_request_reference_id_in_source_verification_flow";/// Check whether the merchant has configured to disable the webhook `event` for the `connector`-/// First check for the key "whconf_{merchant_id}_{connector_id}" in redis,-/// if not found, fetch from configs table in database+/// Uses superposition with dimensions [merchant_id, connector, incoming_webhook_events]pub async fn is_webhook_event_disabled(- db: &dyn StorageInterface,- connector_id: &str,- merchant_id: &common_utils::id_type::MerchantId,+ state: &SessionState,+ connector: common_enums::connector_enums::Connector,+ dimensions: &dimension_state::DimensionsWithProcessorAndProviderMerchantId,event: &api::IncomingWebhookEvent,) -> bool {- let redis_key = merchant_id.get_webhook_config_disabled_events_key(connector_id);- let merchant_webhook_disable_config_result: CustomResult<- api::MerchantWebhookConfig,- redis_interface::errors::RedisError,- > = get_and_deserialize_key(db, &redis_key, "MerchantWebhookConfig").await;+ let dimensions = dimensions+ .with_connector(connector)+ .with_incoming_webhook_event(*event);- match merchant_webhook_disable_config_result {- Ok(merchant_webhook_config) => merchant_webhook_config.contains(event),- Err(..) => {- //if failed to fetch from redis. fetch from db and populate redis- db.find_config_by_key(&redis_key)- .await- .map(|config| {- match serde_json::from_str::<api::MerchantWebhookConfig>(&config.config) {- Ok(set) => set.contains(event),- Err(err) => {- logger::warn!(?err, "error while parsing merchant webhook config");- false- }- }- })- .unwrap_or_else(|err| {- logger::warn!(?err, "error while fetching merchant webhook config");- false- })- }- }+ dimensions+ .get_incoming_webhook_disabled_events(+ state.store.as_ref(),+ state.superposition_service.as_ref(),+ None,+ )+ .await}pub async fn construct_webhook_router_data(