Skip to content

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

feat(superposition): Fetch card testing guard configuration from Superposition (#15147)

Aniket Burmanc14e0e1b7023
diff --git a/config/superposition_seed.toml b/config/superposition_seed.toml
index 4b2c6d22c8..37c06d0b77 100644
--- a/config/superposition_seed.toml
+++ b/config/superposition_seed.toml
@@ -2689,6 +2689,7 @@ pt_mapping_outgoing_connector_webhooks = { value = { default_mapping = { frequen
"vaulting.fingerprint_secret" = { value = "", schema = { type = "string" }, description = "Fingerprint secret used as a migration fallback for merchant accounts", change_reason = "Retain during merchant account migration" }
"payments.should_call_gsm" = { value = false, schema = { type = "boolean" }, description = "Whether to call GSM (Global Status Mapping) for auto-retries on payment failure", change_reason = "Initial setup" }
"payments.payment_blocklist_guard" = { value = false, schema = { type = "boolean" }, description = "Whether the blocklist guard runs during payment confirm, eligibility checks, and saved-card filtering; supports merchant and profile overrides", change_reason = "Initial setup" }
+"payments.card_testing_guard_config" = { value = {}, schema = { type = "object" }, description = "Default card testing guard configuration", change_reason = "Initial setup" }
"system.payment_integration_type" = { value = "client", schema = { type = "string", enum = [
"client",
"server",
diff --git a/crates/router/src/consts.rs b/crates/router/src/consts.rs
index b51678a392..5c336b593c 100644
--- a/crates/router/src/consts.rs
+++ b/crates/router/src/consts.rs
@@ -458,6 +458,8 @@ pub mod superposition {
pub const IMPLICIT_CUSTOMER_UPDATE: &str = "payments.implicit_customer_update";
/// Blocklist guard configuration key: when true, payments are screened against the merchant's blocklist
pub const PAYMENT_BLOCKLIST_GUARD: &str = "payments.payment_blocklist_guard";
+ /// Card testing guard configuration key
+ pub const CARD_TESTING_GUARD_CONFIG: &str = "payments.card_testing_guard_config";
/// Organization-scoped block implicit customer creation configuration key
pub const BLOCK_IMPLICIT_CUSTOMER_CREATION: &str = "payments.block_implicit_customer_creation";
/// Resolve the `customer_id` of a payments request through the `merchant_reference_id` of the
diff --git a/crates/router/src/core/card_testing_guard/utils.rs b/crates/router/src/core/card_testing_guard/utils.rs
index 2b1309f4d8..a940fda3c7 100644
--- a/crates/router/src/core/card_testing_guard/utils.rs
+++ b/crates/router/src/core/card_testing_guard/utils.rs
@@ -7,10 +7,10 @@ use router_env::logger;
use super::errors;
use crate::{
- core::{errors::RouterResult, payments::helpers},
+ core::{configs::dimension_state, errors::RouterResult, payments::helpers},
routes::SessionState,
services,
- types::domain,
+ types::{domain, transformers::ForeignInto},
utils::crypto::{self, SignMessage},
};
@@ -21,8 +21,30 @@ pub async fn validate_card_testing_guard_checks(
card_number: cards::CardNumber,
customer_id: &Option<common_utils::id_type::CustomerId>,
business_profile: &domain::Profile,
+ dimensions: &dimension_state::DimensionsWithProcessorMerchantIdAndOrgIdAndProfileId,
) -> RouterResult<Option<CardTestingGuardData>> {
- match &business_profile.card_testing_guard_config {
+ let superposition_config = dimensions
+ .get_card_testing_guard_config(
+ state.store.as_ref(),
+ state.superposition_service.as_ref(),
+ None,
+ )
+ .await;
+
+ let card_testing_guard_config = if superposition_config == serde_json::json!({}) {
+ business_profile.card_testing_guard_config.clone()
+ } else {
+ Some(
+ serde_json::from_value::<api_models::admin::CardTestingGuardConfig>(
+ superposition_config,
+ )
+ .change_context(errors::ApiErrorResponse::InternalServerError)
+ .attach_printable("Invalid card testing guard config received from Superposition")?
+ .foreign_into(),
+ )
+ };
+
+ match card_testing_guard_config.as_ref() {
Some(card_testing_guard_config) => {
let fingerprint = generate_fingerprint(card_number, business_profile).await?;
diff --git a/crates/router/src/core/configs/dimension_config.rs b/crates/router/src/core/configs/dimension_config.rs
index daf3166e92..22c35661f3 100644
--- a/crates/router/src/core/configs/dimension_config.rs
+++ b/crates/router/src/core/configs/dimension_config.rs
@@ -379,6 +379,22 @@ impl DatabaseBackedConfig for PaymentBlocklistGuard {
}
}
+// Keep an empty object as the application fallback during migration. The card testing guard
+// runtime uses it to distinguish a missing Superposition config from an actual config, then
+// falls back to the legacy business profile value.
+config! {
+ superposition_key = CARD_TESTING_GUARD_CONFIG,
+ output = serde_json::Value,
+ default = serde_json::json!({}),
+ object = true,
+ requires = dimension_state::DimensionsWithProcessorMerchantIdAndOrgIdAndProfileId,
+ targeting_key = id_type::MerchantId
+}
+
+impl DatabaseBackedConfig for CardTestingGuardConfig {
+ const KEY: &'static str = "card_testing_guard_config";
+}
+
config! {
superposition_key = GSM_PAYOUT_CALL,
output = bool,
diff --git a/crates/router/src/core/configs/dimension_state.rs b/crates/router/src/core/configs/dimension_state.rs
index d16c8ad683..ba5eff8810 100644
--- a/crates/router/src/core/configs/dimension_state.rs
+++ b/crates/router/src/core/configs/dimension_state.rs
@@ -777,6 +777,16 @@ pub type DimensionsWithProcessorAndProviderMerchantIdAndOrgIdAndProfileId = Dime
NoWebhookEvent,
NoPaymentMethodType,
>;
+pub type DimensionsWithProcessorMerchantIdAndOrgIdAndProfileId = Dimensions<
+ NoProviderMerchantId,
+ HasProcessorMerchantId,
+ HasOrgId,
+ HasProfileId,
+ NoConnector,
+ NoPayoutRetryType,
+ NoWebhookEvent,
+ NoPaymentMethodType,
+>;
pub type DimensionsWithProcessorAndProviderMerchantIdAndPayoutRetryType = Dimensions<
HasProviderMerchantId,
HasProcessorMerchantId,
diff --git a/crates/router/src/core/payments.rs b/crates/router/src/core/payments.rs
index e268ffc3b8..c3ff40042b 100644
--- a/crates/router/src/core/payments.rs
+++ b/crates/router/src/core/payments.rs
@@ -877,10 +877,20 @@ where
payment_data.set_previous_db_records(previous_attempt, previous_intent);
let dimensions = dimensions.with_profile_id(business_profile.get_id().clone());
+ let dimensions_with_org = dimensions
+ .with_organization_id(platform.get_processor().get_account().get_org_id().clone())
+ .without_provider_merchant_id()
+ .clone();
operation
.to_get_tracker()?
- .validate_request_with_state(state, &req, &mut payment_data, &business_profile)
+ .validate_request_with_state(
+ state,
+ &req,
+ &mut payment_data,
+ &business_profile,
+ &dimensions_with_org,
+ )
.await?;
core_utils::validate_profile_id_from_auth_layer(
@@ -15177,10 +15187,15 @@ impl EligibilityCheck for CardTestingCheck {
async fn execute_check(
&self,
state: &SessionState,
- _platform: &domain::Platform,
+ platform: &domain::Platform,
payment_elgibility_data: &PaymentEligibilityData,
business_profile: &domain::Profile,
) -> CustomResult<CheckResult, errors::ApiErrorResponse> {
+ let dimensions = Dimensions::new()
+ .with_processor_merchant_id(platform.get_processor().get_processor_merchant_id())
+ .with_organization_id(platform.get_processor().get_account().get_org_id().clone())
+ .with_profile_id(business_profile.get_id().clone());
+
match &payment_elgibility_data.payment_method_data {
Some(domain::EligibilityPaymentMethodData::Card(card)) => {
match card_testing_guard_utils::validate_card_testing_guard_checks(
@@ -15192,6 +15207,7 @@ impl EligibilityCheck for CardTestingCheck {
card.card_number.clone(),
&payment_elgibility_data.payment_intent.customer_id,
business_profile,
+ &dimensions,
)
.await
{
diff --git a/crates/router/src/core/payments/operations.rs b/crates/router/src/core/payments/operations.rs
index 07c48ee038..2cd2d849c1 100644
--- a/crates/router/src/core/payments/operations.rs
+++ b/crates/router/src/core/payments/operations.rs
@@ -431,6 +431,7 @@ pub trait GetTracker<F: Clone, D, R>: Send {
_request: &R,
_payment_data: &mut D,
_business_profile: &domain::Profile,
+ _dimensions: &dimension_state::DimensionsWithProcessorMerchantIdAndOrgIdAndProfileId,
) -> RouterResult<()> {
Ok(())
}
diff --git a/crates/router/src/core/payments/operations/payment_cancel_post_capture.rs b/crates/router/src/core/payments/operations/payment_cancel_post_capture.rs
index 9d050fdc5b..003141c1b8 100644
--- a/crates/router/src/core/payments/operations/payment_cancel_post_capture.rs
+++ b/crates/router/src/core/payments/operations/payment_cancel_post_capture.rs
@@ -239,6 +239,7 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsCancelPo
_request: &api::PaymentsCancelPostCaptureRequest,
payment_data: &mut PaymentData<F>,
_business_profile: &domain::Profile,
+ _dimensions: &dimension_state::DimensionsWithProcessorMerchantIdAndOrgIdAndProfileId,
) -> RouterResult<()> {
crate::utils::when(
payment_data.payment_intent.is_post_capture_void_attempted(),
diff --git a/crates/router/src/core/payments/operations/payment_cancel_post_capture_sync.rs b/crates/router/src/core/payments/operations/payment_cancel_post_capture_sync.rs
index 84c3773da1..125470384b 100644
--- a/crates/router/src/core/payments/operations/payment_cancel_post_capture_sync.rs
+++ b/crates/router/src/core/payments/operations/payment_cancel_post_capture_sync.rs
@@ -9,7 +9,10 @@ use router_env::{instrument, tracing};
use super::{BoxedOperation, Domain, GetTracker, Operation, UpdateTracker, ValidateRequest};
use crate::{
core::{
- configs::dimension_state::DimensionsWithProcessorAndProviderMerchantId,
+ configs::dimension_state::{
+ DimensionsWithProcessorAndProviderMerchantId,
+ DimensionsWithProcessorMerchantIdAndOrgIdAndProfileId,
+ },
errors::{self, RouterResult, StorageErrorExt},
payments::{self, helpers, operations, PaymentData},
},
@@ -218,6 +221,7 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, id_type::PaymentId>
_request: &id_type::PaymentId,
payment_data: &mut PaymentData<F>,
_business_profile: &domain::Profile,
+ _dimensions: &DimensionsWithProcessorMerchantIdAndOrgIdAndProfileId,
) -> RouterResult<()> {
let is_post_capture_void_pending = payment_data
.payment_intent
diff --git a/crates/router/src/core/payments/operations/payment_confirm.rs b/crates/router/src/core/payments/operations/payment_confirm.rs
index ddbbd5f47a..2787e8b028 100644
--- a/crates/router/src/core/payments/operations/payment_confirm.rs
+++ b/crates/router/src/core/payments/operations/payment_confirm.rs
@@ -1058,6 +1058,7 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsRequest>
request: &api::PaymentsRequest,
payment_data: &mut PaymentData<F>,
business_profile: &domain::Profile,
+ dimensions: &dimension_state::DimensionsWithProcessorMerchantIdAndOrgIdAndProfileId,
) -> RouterResult<()> {
let payment_method_data: Option<&api_models::payments::PaymentMethodData> = request
.payment_method_data
@@ -1077,6 +1078,7 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsRequest>
card.card_number.clone(),
customer_id,
business_profile,
+ dimensions,
)
.await?;
Ok(())
@@ -1089,6 +1091,7 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsRequest>
card.card_number.clone(),
customer_id,
business_profile,
+ dimensions,
)
.await?;
Ok(())