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): migrate blocklist guard toggle to superposition (#13529)

Ayush Anand7a348f02a94e
diff --git a/config/superposition_seed.toml b/config/superposition_seed.toml
index 12ee501a98..6915424701 100644
--- a/config/superposition_seed.toml
+++ b/config/superposition_seed.toml
@@ -2677,6 +2677,7 @@ pt_mapping_outgoing_connector_webhooks = { value = { default_mapping = { frequen
"vaulting.save_wallet_decrypted_data" = { value = false, schema = { type = "boolean" }, description = "Whether to save wallet decrypted data", change_reason = "Initial setup" }
"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" }
"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 c0a9cc1b14..b52c7807d8 100644
--- a/crates/router/src/consts.rs
+++ b/crates/router/src/consts.rs
@@ -431,6 +431,8 @@ pub mod superposition {
pub const REQUIRES_CVV: &str = "payments.requires_cvv";
/// implicit customer update configuration key
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";
/// Organization-scoped block implicit customer creation configuration key
pub const BLOCK_IMPLICIT_CUSTOMER_CREATION: &str = "payments.block_implicit_customer_creation";
/// Fingerprint secret configuration key retained for migration fallback
diff --git a/crates/router/src/core/blocklist/utils.rs b/crates/router/src/core/blocklist/utils.rs
index 61cbfb41fc..661adba578 100644
--- a/crates/router/src/core/blocklist/utils.rs
+++ b/crates/router/src/core/blocklist/utils.rs
@@ -618,28 +618,6 @@ pub async fn check_blocklist(
Ok(block_reason)
}
-/// Whether the merchant has enabled the blocklist guard (the same config key that gates
-/// confirm-time and eligibility-time blocklist checks). Defaults to `false` when unset.
-pub async fn is_blocklist_guard_enabled(
- state: &SessionState,
- processor_merchant_id: &common_utils::id_type::MerchantId,
-) -> bool {
- let blocklist_enabled_key = processor_merchant_id.get_blocklist_guard_key();
- match state
- .store
- .find_config_by_key_unwrap_or(&blocklist_enabled_key, "false".to_string())
- .await
- {
- Ok(config) => serde_json::from_str(&config.config).unwrap_or(false),
- Err(error) => {
- if !error.current_context().is_db_not_found() {
- logger::error!(?error, "Error fetching blocklist guard enabled config");
- }
- false
- }
- }
-}
-
/// Returns the subset of `bins` (card ISINs / extended BINs) that have an active BIN
/// blocklist entry (BIN kinds only — PAN-fingerprint entries cannot be matched from a
/// BIN) for this merchant/profile, resolved with a single batched query. Merchant-wide
diff --git a/crates/router/src/core/configs.rs b/crates/router/src/core/configs.rs
index ebff7cac48..67bf038a3a 100644
--- a/crates/router/src/core/configs.rs
+++ b/crates/router/src/core/configs.rs
@@ -2,9 +2,9 @@ pub mod dimension_config;
pub mod dimension_state;
use common_utils::errors::CustomResult;
pub use dimension_config::{
- BlockImplicitCustomerCreation, EnableExtendedCardBin, ImplicitCustomerUpdate, RequiresCvv,
- ShouldCallGsm, ShouldEnableMitWithLimitedCardData, ShouldPerformEligibility,
- ShouldStoreEligibilityCheckDataForAuthentication,
+ BlockImplicitCustomerCreation, EnableExtendedCardBin, ImplicitCustomerUpdate,
+ PaymentBlocklistGuard, RequiresCvv, ShouldCallGsm, ShouldEnableMitWithLimitedCardData,
+ ShouldPerformEligibility, ShouldStoreEligibilityCheckDataForAuthentication,
};
use error_stack::ResultExt;
use external_services::superposition;
diff --git a/crates/router/src/core/configs/dimension_config.rs b/crates/router/src/core/configs/dimension_config.rs
index 442c4d372f..afb6b01966 100644
--- a/crates/router/src/core/configs/dimension_config.rs
+++ b/crates/router/src/core/configs/dimension_config.rs
@@ -311,6 +311,25 @@ impl DatabaseBackedConfig for EnableExtendedCardBin {
}
}
+config! {
+ superposition_key = PAYMENT_BLOCKLIST_GUARD,
+ output = bool,
+ default = false,
+ requires = dimension_state::DimensionsWithProcessorAndProviderMerchantIdAndProfileId,
+ targeting_key = id_type::ProfileId
+}
+
+impl DatabaseBackedConfig for PaymentBlocklistGuard {
+ const KEY: &'static str = "payment_blocklist_guard";
+
+ fn db_key(dimensions: &impl dimension_state::DimensionsBase) -> Option<String> {
+ // Retain the legacy merchant key used by the blocklist toggle API.
+ dimensions
+ .get_processor_merchant_id()
+ .map(|id| id.get_blocklist_guard_key())
+ }
+}
+
config! {
superposition_key = GSM_PAYOUT_CALL,
output = bool,
diff --git a/crates/router/src/core/payment_methods/client.rs b/crates/router/src/core/payment_methods/client.rs
index c92aa1224a..3a876bc86e 100644
--- a/crates/router/src/core/payment_methods/client.rs
+++ b/crates/router/src/core/payment_methods/client.rs
@@ -568,8 +568,9 @@ fn filter_customer_pms_by_enabled(
/// Filter out saved cards whose BIN (`card_isin`) has an active blocklist entry for this
/// merchant/profile (merchant-wide entries with a NULL `profile_id` match every profile).
-/// Runs only when the merchant has enabled the blocklist guard (the same config
-/// key that gates confirm-time and eligibility-time blocklist checks). BIN lookups are
+/// Runs only when the merchant has enabled the blocklist guard (the same
+/// `payments.payment_blocklist_guard` config that gates confirm-time and eligibility-time
+/// blocklist checks). BIN lookups are
/// deduplicated across the list and run concurrently. Non-card payment methods and cards
/// without a stored `card_isin` are passed through unchanged — fingerprint-level (exact
/// card) blocklist entries cannot be evaluated at list time since the stored record does
@@ -581,8 +582,16 @@ async fn filter_customer_pms_by_blocklist(
customer_pms: Vec<CustomerPaymentMethodForClient>,
) -> Vec<CustomerPaymentMethodForClient> {
let processor = platform.get_processor();
- let guard_enabled =
- blocklist_utils::is_blocklist_guard_enabled(state, processor.get_account().get_id()).await;
+ let guard_enabled = dimension_state::Dimensions::new()
+ .with_processor_merchant_id(processor.get_processor_merchant_id())
+ .with_provider_merchant_id(platform.get_provider().get_provider_merchant_id())
+ .with_profile_id(profile_id.clone())
+ .get_payment_blocklist_guard(
+ state.store.as_ref(),
+ state.superposition_service.as_ref(),
+ None,
+ )
+ .await;
let bins: std::collections::HashSet<String> = if guard_enabled {
customer_pms
diff --git a/crates/router/src/core/payments.rs b/crates/router/src/core/payments.rs
index 9db2241eec..a306b0e848 100644
--- a/crates/router/src/core/payments.rs
+++ b/crates/router/src/core/payments.rs
@@ -8374,6 +8374,7 @@ pub async fn get_merchant_bank_data_for_open_banking_connectors(
Ok(final_recipient_data)
}
+#[cfg(feature = "v1")]
async fn blocklist_guard<F, ApiRequest, D>(
state: &SessionState,
processor: &domain::Processor,
@@ -8386,25 +8387,15 @@ where
F: Send + Clone + Sync,
D: OperationSessionGetters<F> + OperationSessionSetters<F> + Send + Sync + Clone,
{
- let processor_merchant_id = processor.get_account().get_id();
- let blocklist_enabled_key = processor_merchant_id.get_blocklist_guard_key();
- let blocklist_guard_enabled = state
- .store
- .find_config_by_key_unwrap_or(&blocklist_enabled_key, "false".to_string())
+ let blocklist_guard_enabled = dimensions
+ .with_profile_id(business_profile.get_id().clone())
+ .get_payment_blocklist_guard(
+ state.store.as_ref(),
+ state.superposition_service.as_ref(),
+ None,
+ )
.await;
- let blocklist_guard_enabled: bool = match blocklist_guard_enabled {
- Ok(config) => serde_json::from_str(&config.config).unwrap_or(false),
-
- // If it is not present in db we are defaulting it to false
- Err(inner) => {
- if !inner.current_context().is_db_not_found() {
- logger::error!("Error fetching guard blocklist enabled config {:?}", inner);
- }
- false
- }
- };
-
if blocklist_guard_enabled {
Ok(operation
.to_domain()?
@@ -14346,6 +14337,7 @@ trait EligibilityCheck {
&self,
state: &SessionState,
platform: &domain::Platform,
+ profile_id: &id_type::ProfileId,
) -> CustomResult<bool, errors::ApiErrorResponse>;
// Run the actual check and return the SDK Next Action if applicable
@@ -14397,9 +14389,20 @@ impl EligibilityCheck for BlockListCheck {
&self,
state: &SessionState,
platform: &domain::Platform,
+ profile_id: &id_type::ProfileId,
) -> CustomResult<bool, errors::ApiErrorResponse> {
- let merchant_id = platform.get_processor().get_account().get_id();
- Ok(blocklist_utils::is_blocklist_guard_enabled(state, merchant_id).await)
+ 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_profile_id(profile_id.clone());
+
+ Ok(dimensions
+ .get_payment_blocklist_guard(
+ state.store.as_ref(),
+ state.superposition_service.as_ref(),
+ None,
+ )
+ .await)
}
async fn execute_check(
@@ -14494,6 +14497,7 @@ impl EligibilityCheck for CardTestingCheck {
&self,
_state: &SessionState,
_platform: &domain::Platform,
+ _profile_id: &id_type::ProfileId,
) -> CustomResult<bool, errors::ApiErrorResponse> {
// This check is always run as there is no runtime config enablement
Ok(true)
@@ -14575,7 +14579,9 @@ impl EligibilityHandler {
&self,
check: C,
) -> CustomResult<Option<api_models::payments::SdkNextAction>, errors::ApiErrorResponse> {
- let should_run = check.should_run(&self.state, &self.platform).await?;
+ let should_run = check
+ .should_run(&self.state, &self.platform, self.business_profile.get_id())
+ .await?;
Ok(match should_run {
true => check
.execute_check(
diff --git a/cypress-tests/cypress/e2e/spec/Payment/35-PaymentsEligibilityAPI.cy.js b/cypress-tests/cypress/e2e/spec/Payment/35-PaymentsEligibilityAPI.cy.js
index ed962081ef..e4f399bfbd 100644
--- a/cypress-tests/cypress/e2e/spec/Payment/35-PaymentsEligibilityAPI.cy.js
+++ b/cypress-tests/cypress/e2e/spec/Payment/35-PaymentsEligibilityAPI.cy.js
@@ -4,14 +4,67 @@ import { connectorDetails } from "../../../e2e/configs/Payment/Commons";
let globalState;
+const blocklistContext = () => ({
+ processor_merchant_id: globalState.get("merchantId"),
+ provider_merchant_id: globalState.get("merchantId"),
+});
+
+const profileBlocklistContext = () => ({
+ ...blocklistContext(),
+ profile_id: globalState.get("profileId"),
+});
+
+const blocklistedCardAllowed = {
+ Request: connectorDetails.eligibility_api.BlocklistedCardDenied.Request,
+ Response: {
+ status: 200,
+ body: {},
+ },
+};
+
describe("Payments Eligibility API with Blocklist", () => {
+ let specShouldSkip = false;
+
before("seed global state", () => {
cy.task("getGlobalState").then((state) => {
globalState = new State(state);
+ if (
+ !globalState.get("superpositionBaseUrl") ||
+ !globalState.get("superpositionSecret") ||
+ !globalState.get("superpositionAuthToken")
+ ) {
+ cy.task(
+ "cli_log",
+ "Superposition credentials not set — skipping blocklist spec"
+ );
+ specShouldSkip = true;
+ return;
+ }
+ expect(globalState.get("merchantId"), "merchant ID").to.be.a("string").and
+ .not.be.empty;
+ expect(globalState.get("profileId"), "profile ID").to.be.a("string").and
+ .not.be.empty;
});
});
- after("flush global state", () => {
+ beforeEach(function () {
+ if (specShouldSkip) {
+ this.skip();
+ }
+ });
+
+ after("cleanup superposition config + flush global state", () => {
+ if (!specShouldSkip && globalState?.get("merchantId")) {
+ if (globalState.get("profileId")) {
+ cy.deleteSuperpositionConfig(globalState, profileBlocklistContext());
+ }
+ cy.setSuperpositionConfig(
+ globalState,
+ "payments.payment_blocklist_guard",
+ false,
+ blocklistContext()
+ );
+ }
cy.task("setGlobalState", globalState.data);
});
@@ -36,12 +89,13 @@ describe("Payments Eligibility API with Blocklist", () => {
);
});
- it("should enable blocklist functionality using configs API", () => {
- const merchantId = globalState.get("merchantId");
- const key = `guard_blocklist_for_${merchantId}`;
- const value = "true";
-
- cy.setConfigs(globalState, key, value, "CREATE");
+ it("should enable blocklist functionality using Superposition", () => {
+ cy.setSuperpositionConfig(
+ globalState,
+ "payments.payment_blocklist_guard",
+ true,
+ blocklistContext()
+ );
});
});
@@ -63,17 +117,59 @@ describe("Payments Eligibility API with Blocklist", () => {
});
});
- context("Cleanup", () => {
- it("should delete blocklist rule", () => {
- cy.blocklistDeleteRule("card_bin", "424242", globalState);
+ context("Profile and merchant guard overrides", () => {
+ it("should disable the guard for a profile and inherit the enabled merchant guard after cleanup", () => {
+ cy.setSuperpositionConfig(
+ globalState,
+ "payments.payment_blocklist_guard",
+ false,
+ profileBlocklistContext()
+ );
+ cy.paymentsEligibilityCheck(
+ fixtures.eligibilityCheckBody,
+ blocklistedCardAllowed,
+ globalState
+ );
+
+ cy.deleteSuperpositionConfig(globalState, profileBlocklistContext());
+ cy.paymentsEligibilityCheck(
+ fixtures.eligibilityCheckBody,
+ connectorDetails.eligibility_api.BlocklistedCardDenied,
+ globalState
+ );
});
- it("should disable blocklist functionality using configs API", () => {
- const merchantId = globalState.get("merchantId");
- const key = `guard_blocklist_for_${merchantId}`;
- const value = "true";
+ it("should enable the guard for a profile and inherit the disabled merchant guard after cleanup", () => {
+ cy.setSuperpositionConfig(
+ globalState,
+ "payments.payment_blocklist_guard",
+ false,
+ blocklistContext()
+ );
+ cy.setSuperpositionConfig(
+ globalState,
+ "payments.payment_blocklist_guard",
+ true,
+ profileBlocklistContext()
+ );
+ cy.paymentsEligibilityCheck(
+ fixtures.eligibilityCheckBody,
+ connectorDetails.eligibility_api.BlocklistedCardDenied,
+ globalState
+ );
- cy.setConfigs(globalState, key, value, "DELETE");
+ cy.deleteSuperpositionConfig(globalState, profileBlocklistContext());
+ cy.paymentsEligibilityCheck(
+ fixtures.eligibilityCheckBody,
+ blocklistedCardAllowed,
+ globalState
+ );
+ });
+ });
+
+ context("Cleanup", () => {
+ it("should delete blocklist rule", () => {
+ cy.blocklistDeleteRule("card_bin", "424242", globalState);
});
});
});
diff --git a/cypress-tests/cypress/e2e/spec/Payment/41-CardPaymentBlocking.cy.js b/cypress-tests/cypress/e2e/spec/Payment/41-CardPaymentBlocking.cy.js
index ea64eb57f7..bd3ee4a686 100644
--- a/cypress-tests/cypress/e2e/spec/Payment/41-CardPaymentBlocking.cy.js
+++ b/cypress-tests/cypress/e2e/spec/Payment/41-CardPaymentBlocking.cy.js
@@ -4,14 +4,55 @@ import getConnectorDetails, * as utils from "../../configs/Payment/Utils";
let globalState;
+const blocklistContext = () => ({
+ processor_merchant_id: globalState.get("merchantId"),
+ provider_merchant_id: globalState.get("merchantId"),
+});
+
describe("Business Profile Payment Method Blocking", () => {
+ let specShouldSkip = false;
+
before("seed global state", () => {
cy.task("getGlobalState").then((state) => {
globalState = new State(state);
+ if (
+ !globalState.get("superpositionBaseUrl") ||
+ !globalState.get("superpositionSecret") ||
+ !globalState.get("superpositionAuthToken")
+ ) {
+ cy.task(
+ "cli_log",
+ "Superposition credentials not set — skipping blocklist spec"
+ );
+ specShouldSkip = true;
+ return;
+ }
+ expect(globalState.get("merchantId"), "merchant ID").to.be.a("string").and
+ .not.be.empty;
+ cy.setSuperpositionConfig(
+ globalState,
+ "payments.payment_blocklist_guard",
+ true,
+ blocklistContext()
+ );
});
});
- after("flush global state", () => {
+ beforeEach(function () {
+ if (specShouldSkip) {
+ this.skip();
+ }
+ });
+
+ after("cleanup superposition config + flush global state", () => {
+ if (!specShouldSkip && globalState?.get("merchantId")) {
+ cy.setSuperpositionConfig(
+ globalState,
+ "payments.payment_blocklist_guard",
+ false,
+ blocklistContext()
+ );
+ }
cy.task("setGlobalState", globalState.data);
});
@@ -19,10 +60,6 @@ describe("Business Profile Payment Method Blocking", () => {
it("should block payment when card issuing country is blocked", () => {
let shouldContinue = true;
- cy.step("Enable blocklist", () => {
- cy.blocklistToggle("true", globalState);
- });
-
cy.step("Update business profile to block issuing country", () => {
const updateBusinessProfileBody = {
payment_method_blocking: {
@@ -266,10 +303,6 @@ describe("Business Profile Payment Method Blocking", () => {
);
}
);
-
- cy.step("Disable blocklist", () => {
- cy.blocklistToggle("false", globalState);
- });
});
});
});