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(core): extend profile-based payment method blocking for wallets (#11758)

Vani Guptabd57b6267901
diff --git a/api-reference/v1/openapi_spec_v1.json b/api-reference/v1/openapi_spec_v1.json
index 1d570edf4c..e19e356e15 100644
--- a/api-reference/v1/openapi_spec_v1.json
+++ b/api-reference/v1/openapi_spec_v1.json
@@ -21383,6 +21383,11 @@
"type": "boolean",
"description": "Whether assurance details are required",
"nullable": true
+ },
+ "allow_credit_cards": {
+ "type": "boolean",
+ "description": "Set to false if you don't want to allow credit cards",
+ "nullable": true
}
}
},
@@ -27793,6 +27798,14 @@
}
],
"nullable": true
+ },
+ "wallet": {
+ "allOf": [
+ {
+ "$ref": "#/components/schemas/WalletBlockingConfig"
+ }
+ ],
+ "nullable": true
}
}
},
@@ -42309,6 +42322,20 @@
}
}
},
+ "WalletBlockingConfig": {
+ "type": "object",
+ "description": "Wallet-specific blocking configuration for Apple Pay and Google Pay",
+ "properties": {
+ "card_types": {
+ "type": "array",
+ "items": {
+ "$ref": "#/components/schemas/CardType"
+ },
+ "description": "Set of card types to block for wallet payments (e.g., [\"Credit\", \"Debit\"])",
+ "nullable": true
+ }
+ }
+ },
"WalletData": {
"oneOf": [
{
diff --git a/api-reference/v2/openapi_spec_v2.json b/api-reference/v2/openapi_spec_v2.json
index 8092dc4126..8114426a90 100644
--- a/api-reference/v2/openapi_spec_v2.json
+++ b/api-reference/v2/openapi_spec_v2.json
@@ -15176,6 +15176,11 @@
"type": "boolean",
"description": "Whether assurance details are required",
"nullable": true
+ },
+ "allow_credit_cards": {
+ "type": "boolean",
+ "description": "Set to false if you don't want to allow credit cards",
+ "nullable": true
}
}
},
diff --git a/crates/api_models/src/admin.rs b/crates/api_models/src/admin.rs
index 8d71ef47bf..4ad675124e 100644
--- a/crates/api_models/src/admin.rs
+++ b/crates/api_models/src/admin.rs
@@ -278,6 +278,8 @@ pub struct CardTestingGuardConfig {
pub struct PaymentMethodBlockingConfig {
/// Card-specific blocking configuration
pub card: Option<CardBlockingConfig>,
+ /// Wallet-specific blocking configuration (applies to Apple Pay, Google Pay)
+ pub wallet: Option<WalletBlockingConfig>,
}
/// Card-specific blocking configuration
@@ -299,6 +301,14 @@ pub struct CardBlockingConfig {
pub block_if_bin_info_unavailable: Option<bool>,
}
+/// Wallet-specific blocking configuration for Apple Pay and Google Pay
+#[derive(Clone, Debug, Deserialize, Serialize, ToSchema)]
+pub struct WalletBlockingConfig {
+ /// Set of card types to block for wallet payments (e.g., ["Credit", "Debit"])
+ #[schema(value_type = Option<Vec<CardType>>)]
+ pub card_types: Option<HashSet<common_enums::CardType>>,
+}
+
#[derive(Debug, Clone, serde::Deserialize, serde::Serialize, ToSchema)]
#[serde(rename_all = "snake_case")]
pub enum CardTestingGuardStatus {
diff --git a/crates/api_models/src/payments.rs b/crates/api_models/src/payments.rs
index 2b1deddc72..4205bd934f 100644
--- a/crates/api_models/src/payments.rs
+++ b/crates/api_models/src/payments.rs
@@ -9703,6 +9703,10 @@ pub struct GpayAllowedMethodsParameters {
#[serde(skip_serializing_if = "Option::is_none")]
#[smithy(value_type = "Option<bool>")]
pub assurance_details_required: Option<bool>,
+ /// Set to false if you don't want to allow credit cards
+ #[serde(skip_serializing_if = "Option::is_none")]
+ #[smithy(value_type = "Option<bool>")]
+ pub allow_credit_cards: Option<bool>,
}
#[derive(
diff --git a/crates/diesel_models/src/business_profile.rs b/crates/diesel_models/src/business_profile.rs
index b20771c46a..938e26d5b9 100644
--- a/crates/diesel_models/src/business_profile.rs
+++ b/crates/diesel_models/src/business_profile.rs
@@ -949,6 +949,7 @@ common_utils::impl_to_sql_from_sql_json!(RevenueRecoveryAlgorithmData);
#[diesel(sql_type = diesel::sql_types::Jsonb)]
pub struct PaymentMethodBlockingConfig {
pub card: Option<CardBlockingConfig>,
+ pub wallet: Option<WalletBlockingConfig>,
}
/// Card-specific blocking configuration
@@ -967,6 +968,27 @@ pub struct CardBlockingConfig {
pub block_if_bin_info_unavailable: Option<bool>,
}
+/// Wallet-specific blocking configuration for Apple Pay and Google Pay
+#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
+pub struct WalletBlockingConfig {
+ /// Set of card types to block (e.g., ["Credit", "Debit"])
+ pub card_types: Option<HashSet<common_enums::CardType>>,
+}
+
+impl WalletBlockingConfig {
+ pub fn is_credit_blocked(&self) -> bool {
+ self.card_types
+ .as_ref()
+ .is_some_and(|types| types.contains(&common_enums::CardType::Credit))
+ }
+
+ pub fn is_debit_blocked(&self) -> bool {
+ self.card_types
+ .as_ref()
+ .is_some_and(|types| types.contains(&common_enums::CardType::Debit))
+ }
+}
+
impl CardBlockingConfig {
pub fn should_block_if_bin_info_unavailable(&self) -> bool {
self.block_if_bin_info_unavailable.unwrap_or(false)
diff --git a/crates/hyperswitch_connectors/src/connectors/trustpay/transformers.rs b/crates/hyperswitch_connectors/src/connectors/trustpay/transformers.rs
index f856d6bf82..03bf8b6776 100644
--- a/crates/hyperswitch_connectors/src/connectors/trustpay/transformers.rs
+++ b/crates/hyperswitch_connectors/src/connectors/trustpay/transformers.rs
@@ -1597,6 +1597,7 @@ impl From<GpayAllowedMethodsParameters> for api_models::payments::GpayAllowedMet
billing_address_required: None,
billing_address_parameters: None,
assurance_details_required: value.assurance_details_required,
+ allow_credit_cards: None,
}
}
}
diff --git a/crates/openapi/src/openapi.rs b/crates/openapi/src/openapi.rs
index 11383843f1..2c7a828fcb 100644
--- a/crates/openapi/src/openapi.rs
+++ b/crates/openapi/src/openapi.rs
@@ -362,6 +362,7 @@ Never share your secret api keys. Keep them guarded and secure.
api_models::admin::InternalNetworkTokenizationCredentials,
api_models::admin::PaymentMethodBlockingConfig,
api_models::admin::CardBlockingConfig,
+ api_models::admin::WalletBlockingConfig,
api_models::merchant_connector_webhook_management::ConnectorWebhookRegisterRequest,
api_models::merchant_connector_webhook_management::RegisterConnectorWebhookResponse,
api_models::merchant_connector_webhook_management::ConnectorWebhookResponse,
diff --git a/crates/router/src/core/payments/flows/session_flow.rs b/crates/router/src/core/payments/flows/session_flow.rs
index 2dfca8392f..4f0c513c5d 100644
--- a/crates/router/src/core/payments/flows/session_flow.rs
+++ b/crates/router/src/core/payments/flows/session_flow.rs
@@ -492,6 +492,14 @@ async fn create_applepay_session_token(
required_shipping_contact_fields
};
+ #[cfg(feature = "v1")]
+ let wallet_blocking_config = business_profile
+ .payment_method_blocking
+ .as_ref()
+ .and_then(|config| config.wallet.as_ref());
+ #[cfg(feature = "v2")]
+ let wallet_blocking_config = None;
+
// Get apple pay payment request
let applepay_payment_request = get_apple_pay_payment_request(
amount_info,
@@ -501,6 +509,7 @@ async fn create_applepay_session_token(
merchant_business_country,
required_billing_contact_fields,
required_shipping_contact_fields_updated,
+ wallet_blocking_config,
)?;
let apple_pay_session_response = match (
@@ -860,6 +869,7 @@ fn get_apple_pay_amount_info(
Ok(amount_info)
}
+#[allow(clippy::too_many_arguments)]
fn get_apple_pay_payment_request(
amount_info: payment_types::AmountInfo,
payment_request_data: payment_types::PaymentRequestMetadata,
@@ -868,7 +878,13 @@ fn get_apple_pay_payment_request(
merchant_business_country: Option<api_models::enums::CountryAlpha2>,
required_billing_contact_fields: Option<payment_types::ApplePayBillingContactFields>,
required_shipping_contact_fields: Option<payment_types::ApplePayShippingContactFields>,
+ wallet_blocking_config: Option<&diesel_models::business_profile::WalletBlockingConfig>,
) -> RouterResult<payment_types::ApplePayPaymentRequest> {
+ let merchant_capabilities = apply_wallet_blocking_to_apple_pay_capabilities(
+ payment_request_data.merchant_capabilities,
+ wallet_blocking_config,
+ );
+
let applepay_payment_request = payment_types::ApplePayPaymentRequest {
country_code: merchant_business_country.or(session_data.country).ok_or(
errors::ApiErrorResponse::MissingRequiredField {
@@ -877,7 +893,7 @@ fn get_apple_pay_payment_request(
)?,
currency_code: session_data.currency,
total: amount_info,
- merchant_capabilities: Some(payment_request_data.merchant_capabilities),
+ merchant_capabilities: Some(merchant_capabilities),
supported_networks: Some(payment_request_data.supported_networks),
merchant_identifier: Some(merchant_identifier.to_string()),
required_billing_contact_fields,
@@ -887,6 +903,31 @@ fn get_apple_pay_payment_request(
Ok(applepay_payment_request)
}
+/// If credit cards are blocked, add "supportsDebit" capability
+fn apply_wallet_blocking_to_apple_pay_capabilities(
+ mut capabilities: Vec<String>,
+ wallet_blocking_config: Option<&diesel_models::business_profile::WalletBlockingConfig>,
+) -> Vec<String> {
+ if let Some(wallet_config) = wallet_blocking_config {
+ if wallet_config.is_credit_blocked() {
+ capabilities.push("supportsDebit".to_string());
+ }
+ }
+ capabilities
+}
+
+fn get_google_pay_card_type_restrictions(
+ wallet_blocking_config: Option<&diesel_models::business_profile::WalletBlockingConfig>,
+) -> Option<bool> {
+ wallet_blocking_config.and_then(|wallet_config| {
+ if wallet_config.is_credit_blocked() {
+ Some(false)
+ } else {
+ None
+ }
+ })
+}
+
fn create_apple_pay_session_response(
router_data: &types::PaymentsSessionRouterData,
session_response: Option<payment_types::ApplePaySessionResponse>,
@@ -1029,6 +1070,14 @@ fn create_gpay_session_token(
enums::PaymentMethodType::GooglePay,
);
+ #[cfg(feature = "v1")]
+ let wallet_blocking_config = business_profile
+ .payment_method_blocking
+ .as_ref()
+ .and_then(|config| config.wallet.as_ref());
+ #[cfg(feature = "v2")]
+ let wallet_blocking_config = None;
+
if google_pay_wallets_details.is_some() {
let gpay_data = router_data
.connector_wallets_details
@@ -1055,6 +1104,7 @@ fn create_gpay_session_token(
cards,
&gpay_info.merchant_info.tokenization_specification,
is_billing_details_required,
+ wallet_blocking_config,
)?;
Ok(types::PaymentsSessionRouterData {
@@ -1127,6 +1177,9 @@ fn create_gpay_session_token(
.into());
}
};
+
+ let allow_credit_cards = get_google_pay_card_type_restrictions(wallet_blocking_config);
+
let gpay_allowed_payment_methods = gpay_data
.allowed_payment_methods
.into_iter()
@@ -1135,6 +1188,7 @@ fn create_gpay_session_token(
parameters: payment_types::GpayAllowedMethodsParameters {
billing_address_required: Some(is_billing_details_required),
billing_address_parameters: billing_address_parameters.clone(),
+ allow_credit_cards,
..allowed_payment_methods.parameters
},
tokenization_specification: payment_types::GpayTokenizationSpecification {
@@ -1198,6 +1252,7 @@ fn get_allowed_payment_methods_from_cards(
gpay_cards: payment_types::GpayAllowedMethodsParameters,
gpay_token_specific_data: &payment_types::GooglePayTokenizationSpecification,
is_billing_details_required: bool,
+ wallet_blocking_config: Option<&diesel_models::business_profile::WalletBlockingConfig>,
) -> RouterResult<payment_types::GpayAllowedPaymentMethods> {
let billing_address_parameters =
is_billing_details_required.then_some(payment_types::GpayBillingAddressParameters {
@@ -1211,10 +1266,13 @@ fn get_allowed_payment_methods_from_cards(
.as_ref()
.map(|_| PROTOCOL.to_string());
+ let allow_credit_cards = get_google_pay_card_type_restrictions(wallet_blocking_config);
+
Ok(payment_types::GpayAllowedPaymentMethods {
parameters: payment_types::GpayAllowedMethodsParameters {
billing_address_required: Some(is_billing_details_required),
billing_address_parameters: billing_address_parameters.clone(),
+ allow_credit_cards,
..gpay_cards
},
payment_method_type: CARD.to_string(),
diff --git a/crates/router/src/core/unified_connector_service/transformers.rs b/crates/router/src/core/unified_connector_service/transformers.rs
index bf3a65651c..73c0e661ab 100644
--- a/crates/router/src/core/unified_connector_service/transformers.rs
+++ b/crates/router/src/core/unified_connector_service/transformers.rs
@@ -5178,6 +5178,7 @@ impl transformers::ForeignTryFrom<payments_grpc::GpayAllowedMethodsParameters>
.map(GpayBillingAddressParameters::foreign_try_from)
.transpose()?,
assurance_details_required: value.assurance_details,
+ allow_credit_cards: None,
})
}
}
diff --git a/crates/router/src/types/transformers.rs b/crates/router/src/types/transformers.rs
index e0fa749cf6..d236f07b75 100644
--- a/crates/router/src/types/transformers.rs
+++ b/crates/router/src/types/transformers.rs
@@ -2251,6 +2251,7 @@ impl ForeignFrom<api_models::admin::PaymentMethodBlockingConfig>
fn foreign_from(item: api_models::admin::PaymentMethodBlockingConfig) -> Self {
Self {
card: item.card.map(|c| c.foreign_into()),
+ wallet: item.wallet.map(|w| w.foreign_into()),
}
}
}
@@ -2269,12 +2270,23 @@ impl ForeignFrom<api_models::admin::CardBlockingConfig>
}
}
+impl ForeignFrom<api_models::admin::WalletBlockingConfig>
+ for diesel_models::business_profile::WalletBlockingConfig
+{
+ fn foreign_from(item: api_models::admin::WalletBlockingConfig) -> Self {
+ Self {
+ card_types: item.card_types,
+ }
+ }
+}
+
impl ForeignFrom<diesel_models::business_profile::PaymentMethodBlockingConfig>
for api_models::admin::PaymentMethodBlockingConfig
{
fn foreign_from(item: diesel_models::business_profile::PaymentMethodBlockingConfig) -> Self {
Self {
card: item.card.map(|c| c.foreign_into()),
+ wallet: item.wallet.map(|w| w.foreign_into()),
}
}
}
@@ -2293,6 +2305,16 @@ impl ForeignFrom<diesel_models::business_profile::CardBlockingConfig>
}
}
+impl ForeignFrom<diesel_models::business_profile::WalletBlockingConfig>
+ for api_models::admin::WalletBlockingConfig
+{
+ fn foreign_from(item: diesel_models::business_profile::WalletBlockingConfig) -> Self {
+ Self {
+ card_types: item.card_types,
+ }
+ }
+}
+
impl ForeignFrom<api_models::admin::WebhookDetails>
for diesel_models::business_profile::WebhookDetails
{