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(authentication): added tokenisation disable config as org level to merchant level priority (#12839)
Sahkal Poddar48c3545bd97a
diff --git a/config/superposition_seed.toml b/config/superposition_seed.tomlindex e6bf585f1b..77ab7aa316 100644--- a/config/superposition_seed.toml+++ b/config/superposition_seed.toml@@ -262,4 +262,3 @@ max_retries_count = 5[default-configs.pt_mapping_dispute_sync.value.default_mapping]start_after = 60frequencies = [[300, 5]]-diff --git a/crates/router/src/core/configs.rs b/crates/router/src/core/configs.rsindex 34f964dd81..88f0bdcd45 100644--- a/crates/router/src/core/configs.rs+++ b/crates/router/src/core/configs.rs@@ -153,13 +153,13 @@ whereC::Output: ConfigType,open_feature::Client: superposition::GetValue<C::Output>,{- let db_key = <C as DatabaseBackedConfig>::db_key(dimensions);+ let db_keys = <C as DatabaseBackedConfig>::db_keys(dimensions);let context = dimensions.to_superposition_context();fetch_db_config::<C>(storage,superposition_client,- db_key.as_deref(),+ db_keys.iter().map(|k| k.as_deref()).collect(),context,targeting_key,)@@ -173,7 +173,9 @@ pub trait DatabaseBackedConfig: superposition::Config {const KEY: &'static str;/// Generate the database key for this config based on dimensions- fn db_key(dimensions: &impl dimension_state::DimensionsBase) -> Option<String>;+ fn db_key(_dimensions: &impl dimension_state::DimensionsBase) -> Option<String> {+ None+ }/// Parse the raw database config string into the output type./// Override this for configs whose DB format differs from the Output type@@ -184,6 +186,10 @@ pub trait DatabaseBackedConfig: superposition::Config {{Self::Output::from_config_str(config_str).ok()}++ fn db_keys(dimensions: &impl dimension_state::DimensionsBase) -> Vec<Option<String>> {+ vec![Self::db_key(dimensions)]+ }}/// Fetch configuration value from Superposition with database fallback.@@ -192,7 +198,7 @@ pub trait DatabaseBackedConfig: superposition::Config {pub async fn fetch_db_config<C>(storage: &dyn db::StorageInterface,superposition_client: &superposition::SuperpositionClient,- db_key: Option<&str>,+ db_keys: Vec<Option<&str>>,context: Option<ConfigContext>,targeting_key: Option<&C::TargetingKey>,) -> C::Output@@ -216,20 +222,20 @@ where);value}- Err(_) => match db_key {- Some(db_key) => {- router_env::logger::info!(- "Retrieving config from database for key '{}'",- config_type- );-- let config_result = storage.find_config_by_key(db_key).await;-- match config_result- .ok()- .and_then(|config| C::parse_db_config(&config.config, context.as_ref()))- {- Some(value) => {+ Err(_) => {+ // `attempted` tracks if at least one database key was valid (Some) and queried.+ // This determines whether we log that we fallback to defaults or that no key was provided.+ let mut attempted = false;+ let mut resolved_value = None;+ for db_key in db_keys.into_iter().flatten() {+ attempted = true;+ if resolved_value.is_none() {+ let config_result = storage.find_config_by_key(db_key).await;++ if let Some(value) = config_result+ .ok()+ .and_then(|config| C::parse_db_config(&config.config, context.as_ref()))+ {router_env::logger::info!(config_key = %config_type,db_key = %db_key,@@ -240,33 +246,33 @@ where1,router_env::metric_attributes!(("config_type", config_type)),);- value+ resolved_value = Some(value);}- None => {+ }+ }++ match resolved_value {+ Some(value) => value,+ None => {+ if attempted {router_env::logger::info!("Using default config value for key '{}'",config_type);- metrics::CONFIG_DEFAULT_FALLBACK.add(- 1,- router_env::metric_attributes!(("config_type", config_type)),+ } else {+ router_env::logger::info!(+ "No database key provided for config '{}', using default value",+ config_type);- default_value}+ metrics::CONFIG_DEFAULT_FALLBACK.add(+ 1,+ router_env::metric_attributes!(("config_type", config_type)),+ );+ default_value}}- None => {- router_env::logger::info!(- "No database key provided for config '{}', using default value",- config_type- );- metrics::CONFIG_DEFAULT_FALLBACK.add(- 1,- router_env::metric_attributes!(("config_type", config_type)),- );- default_value- }- },+ }}}@@ -275,7 +281,7 @@ wherepub async fn fetch_db_config_object<C, T>(storage: &dyn db::StorageInterface,superposition_client: &superposition::SuperpositionClient,- db_key: Option<&str>,+ db_keys: Vec<Option<&str>>,context: Option<ConfigContext>,targeting_key: Option<&C::TargetingKey>,) -> T@@ -287,7 +293,7 @@ wherelet json_value = fetch_db_config::<C>(storage,superposition_client,- db_key,+ db_keys,context,targeting_key,)@@ -320,13 +326,13 @@ whereT: for<'de> serde::Deserialize<'de> + Default,open_feature::Client: superposition::GetValue<serde_json::Value>,{- let db_key = <C as DatabaseBackedConfig>::db_key(dimensions);+ let db_keys = <C as DatabaseBackedConfig>::db_keys(dimensions);let context = dimensions.to_superposition_context();fetch_db_config_object::<C, T>(storage,superposition_client,- db_key.as_deref(),+ db_keys.iter().map(|k| k.as_deref()).collect(),context,targeting_key,)@@ -346,13 +352,13 @@ whereT: std::str::FromStr,open_feature::Client: superposition::GetValue<String>,{- let db_key = <C as DatabaseBackedConfig>::db_key(dimensions);+ let db_keys = <C as DatabaseBackedConfig>::db_keys(dimensions);let context = dimensions.to_superposition_context();let raw_value = fetch_db_config::<C>(storage,superposition_client,- db_key.as_deref(),+ db_keys.iter().map(|k| k.as_deref()).collect(),context,targeting_key,)diff --git a/crates/router/src/core/configs/dimension_config.rs b/crates/router/src/core/configs/dimension_config.rsindex e7fb7878dd..86acda4601 100644--- a/crates/router/src/core/configs/dimension_config.rs+++ b/crates/router/src/core/configs/dimension_config.rs@@ -371,17 +371,22 @@ config! {superposition_key = SHOULD_DISABLE_VAULT_TOKENIZATION,output = bool,default = false,- requires = dimension_state::DimensionsWithProcessorAndProviderMerchantIdAndProfileId,+ requires = dimension_state::DimensionsWithProcessorAndProviderMerchantIdAndOrgId,targeting_key = id_type::CustomerId}impl DatabaseBackedConfig for ShouldDisableVaultTokenization {const KEY: &'static str = "should_disable_vault_tokenization";- fn db_key(dimensions: &impl dimension_state::DimensionsBase) -> Option<String> {- dimensions- .get_processor_merchant_id()- .map(|id| format!("{}_{}", Self::KEY, id.get_string_repr()))+ fn db_keys(dimensions: &impl dimension_state::DimensionsBase) -> Vec<Option<String>> {+ vec![+ dimensions+ .get_organization_id()+ .map(|id| format!("{}_{}", Self::KEY, id.get_string_repr())),+ dimensions+ .get_processor_merchant_id()+ .map(|id| format!("{}_{}", Self::KEY, id.get_string_repr())),+ ]}}diff --git a/crates/router/src/core/unified_authentication_service.rs b/crates/router/src/core/unified_authentication_service.rsindex 62b626de17..d770700d2e 100644--- a/crates/router/src/core/unified_authentication_service.rs+++ b/crates/router/src/core/unified_authentication_service.rs@@ -2192,11 +2192,10 @@ pub async fn authentication_sync_core(.await?;}- let dimensions = dimensions.without_organization_id();-// Determine whether to tokenise or notlet should_disable_vault_tokenization = dimensions+ .without_profile_id().get_should_disable_vault_tokenization(state.store.as_ref(),state.superposition_service.as_ref(),