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(core): Enable config-based UAS eligibility at org and merchant level (#10996)
awasthi21cedaa079c021
diff --git a/crates/common_utils/src/id_type/merchant.rs b/crates/common_utils/src/id_type/merchant.rsindex 941c79779f..a7126d2fba 100644--- a/crates/common_utils/src/id_type/merchant.rs+++ b/crates/common_utils/src/id_type/merchant.rs@@ -232,6 +232,10 @@ impl MerchantId {),}}+ /// get_authentication_service_eligible_key+ pub fn get_authentication_service_eligible_key(&self) -> String {+ format!("authentication_service_eligible_{}", self.get_string_repr())+ }/// allow payment update via client auth default should be falsepub fn get_payment_update_enabled_for_client_auth_key(&self) -> String {format!(diff --git a/crates/common_utils/src/id_type/organization.rs b/crates/common_utils/src/id_type/organization.rsindex 69ededbb7a..4f8c58373e 100644--- a/crates/common_utils/src/id_type/organization.rs+++ b/crates/common_utils/src/id_type/organization.rs@@ -21,6 +21,10 @@ impl OrganizationId {pub fn try_from_string(org_id: String) -> CustomResult<Self, ValidationError> {Self::try_from(std::borrow::Cow::from(org_id))}+ /// get_authentication_service_eligible_key+ pub fn get_authentication_service_eligible_key(&self) -> String {+ format!("authentication_service_eligible_{}", self.get_string_repr())+ }/// fetch Get threeds_routing_region key for organizationpub fn get_threeds_routing_region_uas_key(&self) -> String {diff --git a/crates/router/src/core/payments.rs b/crates/router/src/core/payments.rsindex bd3d19b8a9..6df476674a 100644--- a/crates/router/src/core/payments.rs+++ b/crates/router/src/core/payments.rs@@ -806,6 +806,7 @@ wherelet is_eligible_for_uas = helpers::is_merchant_eligible_authentication_service(platform.get_processor().get_account().get_id(),+ platform.get_processor().get_account().get_org_id(),state,).await?;@@ -10898,6 +10899,7 @@ pub async fn payment_external_authentication<F: Clone + Sync>(let authentication_response = if helpers::is_merchant_eligible_authentication_service(platform.get_processor().get_account().get_id(),+ platform.get_processor().get_account().get_org_id(),&state,).await?diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rsindex 2ade484d05..45a9f8e683 100644--- a/crates/router/src/core/payments/helpers.rs+++ b/crates/router/src/core/payments/helpers.rs@@ -8392,33 +8392,46 @@ pub fn validate_platform_request_for_marketplace(Ok(())}+/// Returns `true` if either the org or merchant config is set to "true"+///+/// Priority logic:+/// 1. If org-level config exists (either "true" or "false"), that decision is final+/// - Org = "true" → returns true (authentication enabled)+/// - Org = "false" → returns false (authentication disabled, merchant config ignored)+/// 2. If org-level config is missing or fails to fetch, fallback to merchant-level config+/// - Merchant = "true" → returns true+/// - Merchant = "false" or missing → returns false+///+/// This ensures parent (org) rules take precedence over child (merchant) configurationspub async fn is_merchant_eligible_authentication_service(merchant_id: &id_type::MerchantId,+ org_id: &id_type::OrganizationId,state: &SessionState,) -> RouterResult<bool> {- let merchants_eligible_for_authentication_service = state- .store- .as_ref()- .find_config_by_key_unwrap_or(- consts::AUTHENTICATION_SERVICE_ELIGIBLE_CONFIG,- Some("[]".to_string()),- )- .await;-- let auth_eligible_array: Vec<String> = match merchants_eligible_for_authentication_service {- Ok(config) => serde_json::from_str(&config.config)- .change_context(errors::ApiErrorResponse::InternalServerError)- .attach_printable("unable to parse authentication service config")?,- Err(err) => {- logger::error!(- "Error fetching authentication service enabled merchant config {:?}",- err- );- Vec::new()- }- };+ let db = &*state.store;+ let org_key = org_id.get_authentication_service_eligible_key();+ let org_eligible = db+ .find_config_by_key(&org_key)+ .await+ .inspect_err(|error| {+ logger::error!(?error, "Failed to fetch `{org_key}` config from DB");+ })+ .ok()+ .map(|c| c.config.to_lowercase() == "true");- Ok(auth_eligible_array.contains(&merchant_id.get_string_repr().to_owned()))+ Ok(org_eligible+ .async_unwrap_or_else(|| async {+ let merchant_key = merchant_id.get_authentication_service_eligible_key();+ db.find_config_by_key(&merchant_key)+ .await+ .inspect_err(|error| {+ logger::error!(?error, "Failed to fetch `{merchant_key}` config from DB");+ })+ .ok()+ .map(|c| c.config.to_lowercase() == "true")+ .unwrap_or(false)+ })+ .await)}#[cfg(feature = "v1")]diff --git a/crates/router/src/core/webhooks/incoming.rs b/crates/router/src/core/webhooks/incoming.rsindex 89209509d1..c934149735 100644--- a/crates/router/src/core/webhooks/incoming.rs+++ b/crates/router/src/core/webhooks/incoming.rs@@ -503,6 +503,7 @@ async fn fetch_three_ds_execution_path(let is_merchant_eligible_for_uas =payments::helpers::is_merchant_eligible_authentication_service(&platform.get_processor().get_account().get_id().clone(),+ &platform.get_processor().get_account().get_org_id().clone(),state,).await?;