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(payments): run blocklist against decrypted wallet DPAN in eligibility check (#13508)
Ayush Anande857494ec53f
diff --git a/api-reference/v1/openapi_spec_v1.json b/api-reference/v1/openapi_spec_v1.jsonindex dbea25b657..d782b9bdd4 100644--- a/api-reference/v1/openapi_spec_v1.json+++ b/api-reference/v1/openapi_spec_v1.json@@ -45518,7 +45518,8 @@"items": {"$ref": "#/components/schemas/CardType"},- "description": "Set of card types to block for all wallet payments (e.g., [\"Credit\", \"Debit\"]).\nRetained for backwards compatibility with existing configurations.",+ "description": "Set of card types to block for all wallet payments (e.g., [\"Credit\", \"Debit\"]).\n\nDeprecated: this applies one rule to every wallet, so a card type cannot be blocked on\nApple Pay without also blocking it on Google Pay. Use `apple_pay.card_types` and\n`google_pay.card_types` instead, which are evaluated per wallet against that wallet's decrypted card.",+ "deprecated": true,"nullable": true},"apple_pay": {diff --git a/crates/api_models/src/admin.rs b/crates/api_models/src/admin.rsindex 73478b76b8..ed4fb3fa6f 100644--- a/crates/api_models/src/admin.rs+++ b/crates/api_models/src/admin.rs@@ -355,8 +355,11 @@ pub struct CardBlockingConfig {#[derive(Clone, Debug, Deserialize, Serialize, ToSchema)]pub struct WalletBlockingConfig {/// Set of card types to block for all wallet payments (e.g., ["Credit", "Debit"]).- /// Retained for backwards compatibility with existing configurations.- #[schema(value_type = Option<Vec<CardType>>)]+ ///+ /// Deprecated: this applies one rule to every wallet, so a card type cannot be blocked on+ /// Apple Pay without also blocking it on Google Pay. Use `apple_pay.card_types` and+ /// `google_pay.card_types` instead, which are evaluated per wallet against that wallet's decrypted card.+ #[schema(value_type = Option<Vec<CardType>>, deprecated)]pub card_types: Option<HashSet<common_enums::CardType>>,/// Apple Pay-specific blocking configurationpub apple_pay: Option<CardBlockingConfig>,diff --git a/crates/common_enums/src/enums.rs b/crates/common_enums/src/enums.rsindex 36340bd598..f5bbdacb8e 100644--- a/crates/common_enums/src/enums.rs+++ b/crates/common_enums/src/enums.rs@@ -3458,7 +3458,6 @@ pub enum FundingSource {utoipa::ToSchema,)]#[serde(rename_all = "snake_case")]-#[strum(serialize_all = "UPPERCASE")]pub enum CardSegmentType {Business,Commercial,diff --git a/crates/diesel_models/src/business_profile.rs b/crates/diesel_models/src/business_profile.rsindex 3f66690a3b..2a00f67b11 100644--- a/crates/diesel_models/src/business_profile.rs+++ b/crates/diesel_models/src/business_profile.rs@@ -721,16 +721,17 @@ pub struct WalletBlockingConfig {}impl WalletBlockingConfig {- pub fn is_credit_blocked(&self) -> bool {- self.card_types+ /// Per-wallet config only.+ pub fn is_credit_blocked_for_apple_pay(&self) -> bool {+ self.apple_pay.as_ref()- .is_some_and(|types| types.contains(&common_enums::CardType::Credit))+ .is_some_and(CardBlockingConfig::is_credit_blocked)}- pub fn is_debit_blocked(&self) -> bool {- self.card_types+ pub fn is_credit_blocked_for_google_pay(&self) -> bool {+ self.google_pay.as_ref()- .is_some_and(|types| types.contains(&common_enums::CardType::Debit))+ .is_some_and(CardBlockingConfig::is_credit_blocked)}}@@ -739,6 +740,12 @@ impl CardBlockingConfig {self.block_if_bin_info_unavailable.unwrap_or(false)}+ pub fn is_credit_blocked(&self) -> bool {+ self.card_types+ .as_ref()+ .is_some_and(|card_types| card_types.contains(&common_enums::CardType::Credit))+ }+pub fn should_block_by_attribute<T>(blocked: &Option<HashSet<T>>, value: Option<&str>) -> boolwhereT: std::str::FromStr + std::hash::Hash + Eq,diff --git a/crates/hyperswitch_domain_models/src/payment_method_data.rs b/crates/hyperswitch_domain_models/src/payment_method_data.rsindex b5625ccc7f..f651c0afd6 100644--- a/crates/hyperswitch_domain_models/src/payment_method_data.rs+++ b/crates/hyperswitch_domain_models/src/payment_method_data.rs@@ -383,7 +383,7 @@ pub enum EligibilityPaymentMethodData {impl EligibilityPaymentMethodData {pub fn is_eligible_for_profile_config_blocklist(&self) -> bool {- matches!(self, Self::Card(_))+ matches!(self, Self::Card(_) | Self::Wallet(_))}pub fn get_card_iin(&self) -> Option<String> {@@ -392,6 +392,29 @@ impl EligibilityPaymentMethodData {_ => None,}}++ /// 8-digit BIN of a wallet's decrypted token. `None` while the token is still encrypted.+ pub fn get_decrypted_token_extended_bin(&self) -> Option<String> {+ match self {+ Self::Wallet(WalletData::GooglePay(google_pay)) => google_pay+ .tokenization_data+ .get_decrypted_google_pay_payment_data_optional()+ .map(|decrypted_data| {+ decrypted_data+ .application_primary_account_number+ .get_extended_card_bin()+ }),+ Self::Wallet(WalletData::ApplePay(apple_pay)) => apple_pay+ .payment_data+ .get_decrypted_apple_pay_payment_data_optional()+ .map(|decrypted_data| {+ decrypted_data+ .application_primary_account_number+ .get_extended_card_bin()+ }),+ _ => None,+ }+ }}#[derive(PartialEq, Clone, Debug, Serialize, Deserialize, Default)]diff --git a/crates/router/src/core/blocklist/utils.rs b/crates/router/src/core/blocklist/utils.rsindex f7c4124eb1..42a745e641 100644--- a/crates/router/src/core/blocklist/utils.rs+++ b/crates/router/src/core/blocklist/utils.rs@@ -3,7 +3,10 @@ use std::collections::HashSet;use api_models::blocklist as api_blocklist;use common_enums::{BlockReason, MerchantDecision};use common_utils::errors::CustomResult;-use diesel_models::{business_profile::CardBlockingConfig, configs};+use diesel_models::{+ business_profile::{CardBlockingConfig, PaymentMethodBlockingConfig},+ configs,+};use error_stack::ResultExt;use hyperswitch_masking::{PeekInterface, StrongSecret};@@ -379,6 +382,11 @@ pub async fn should_payment_be_blocked(_ => None,});+ // Extended bin of the wallet's decrypted token, to check whether or not this payment should be blocked.+ let decrypted_token_extended_bin = payment_method_data+ .as_ref()+ .and_then(|pm_data| pm_data.get_decrypted_token_extended_bin());+//validating the payment method.let mut blocklist_futures = Vec::new();if let Some(card_number_fingerprint) = card_number_fingerprint.as_ref() {@@ -408,6 +416,15 @@ pub async fn should_payment_be_blocked();}+ if let Some(decrypted_token_extended_bin) = decrypted_token_extended_bin.as_ref() {+ blocklist_futures.push(+ db.find_blocklist_entry_by_processor_merchant_id_fingerprint_id(+ processor_merchant_id,+ decrypted_token_extended_bin,+ ),+ );+ }+let blocklist_lookups = futures::future::join_all(blocklist_futures).await;let mut block_reason: Option<BlockReason> = None;@@ -516,6 +533,37 @@ where}}+/// Pick the blocking config slot and the BIN that addresses `cards_info` for this payment method.+fn resolve_blocking_config_and_bin<'a>(+ blocking_config: &'a PaymentMethodBlockingConfig,+ payment_method_data: &domain::EligibilityPaymentMethodData,+) -> Option<(&'a CardBlockingConfig, String)> {+ match payment_method_data {+ domain::EligibilityPaymentMethodData::Card(card) => blocking_config+ .card+ .as_ref()+ .map(|card_config| (card_config, card.card_number.get_card_isin())),++ domain::EligibilityPaymentMethodData::Wallet(domain::WalletData::ApplePay(_)) => {+ blocking_config+ .wallet+ .as_ref()+ .and_then(|wallet_config| wallet_config.apple_pay.as_ref())+ .zip(payment_method_data.get_decrypted_token_extended_bin())+ }++ domain::EligibilityPaymentMethodData::Wallet(domain::WalletData::GooglePay(_)) => {+ blocking_config+ .wallet+ .as_ref()+ .and_then(|wallet_config| wallet_config.google_pay.as_ref())+ .zip(payment_method_data.get_decrypted_token_extended_bin())+ }++ _ => None,+ }+}+pub async fn should_payment_be_blocked_by_profile_config(state: &SessionState,payment_method_data: &Option<domain::EligibilityPaymentMethodData>,@@ -523,21 +571,13 @@ pub async fn should_payment_be_blocked_by_profile_config() -> CustomResult<Option<BlockReason>, errors::ApiErrorResponse> {let mut block_reason: Option<BlockReason> = None;- let card_config = business_profile+ let config_and_bin = business_profile.payment_method_blocking.as_ref()- .and_then(|config| config.card.as_ref());-- let card_isin = payment_method_data- .as_ref()- .and_then(|pm_data| match pm_data {- domain::EligibilityPaymentMethodData::Card(card) => {- Some(card.card_number.get_card_isin())- }- _ => None,- });+ .zip(payment_method_data.as_ref())+ .and_then(|(blocking_config, pmd)| resolve_blocking_config_and_bin(blocking_config, pmd));- if let (Some(card_config), Some(card_isin)) = (card_config, card_isin) {+ if let Some((card_config, card_isin)) = config_and_bin {let CardBlockingConfig {issuing_country,card_types,diff --git a/crates/router/src/core/payments.rs b/crates/router/src/core/payments.rsindex e6343d44ef..6a50a38c1f 100644--- a/crates/router/src/core/payments.rs+++ b/crates/router/src/core/payments.rs@@ -7511,33 +7511,11 @@ where"Apple Pay wallet data not found in the payment method data during the Apple Pay decryption flow",)?;- let apple_pay_data =- ApplePayData::token_json(domain::WalletData::ApplePay(apple_pay_wallet_data.clone()))- .change_context(errors::ApiErrorResponse::InternalServerError)- .attach_printable("failed to parse apple pay token to json")?- .decrypt(- &apple_pay_payment_processing_details.payment_processing_certificate,- &apple_pay_payment_processing_details.payment_processing_certificate_key,- )- .await- .change_context(errors::ApiErrorResponse::InternalServerError)- .attach_printable("failed to decrypt apple pay token")?;-- let apple_pay_predecrypt_internal = apple_pay_data- .parse_value::<hyperswitch_domain_models::router_data::ApplePayPredecryptDataInternal>(- "ApplePayPredecryptDataInternal",- )- .change_context(errors::ApiErrorResponse::InternalServerError)- .attach_printable(- "failed to parse decrypted apple pay response to ApplePayPredecryptData",- )?;-- let apple_pay_predecrypt =- common_types::payments::ApplePayPredecryptData::try_from(apple_pay_predecrypt_internal)- .change_context(errors::ApiErrorResponse::InternalServerError)- .attach_printable(- "failed to convert ApplePayPredecryptDataInternal to ApplePayPredecryptData",- )?;+ let apple_pay_predecrypt = decrypt_apple_pay_wallet_data(+ apple_pay_payment_processing_details,+ apple_pay_wallet_data,+ )+ .await?;Ok(PaymentMethodToken::ApplePayDecrypt(Box::new(apple_pay_predecrypt,@@ -7622,40 +7600,82 @@ where"Google Pay wallet data not found in the payment method data during the Google Pay decryption flow",)?;- let decryptor = helpers::GooglePayTokenDecryptor::new(- google_pay_payment_processing_details- .google_pay_root_signing_keys- .clone(),- google_pay_payment_processing_details- .google_pay_recipient_id- .clone(),- google_pay_payment_processing_details- .google_pay_private_key- .clone(),+ let google_pay_data = decrypt_google_pay_wallet_data(+ google_pay_payment_processing_details,+ google_pay_wallet_data,)- .change_context(errors::ApiErrorResponse::InternalServerError)- .attach_printable("failed to create google pay token decryptor")?;-- // should_verify_token is set to false to disable verification of token- let google_pay_data_internal = decryptor- .decrypt_token(- google_pay_wallet_data- .tokenization_data- .get_encrypted_google_pay_token()- .change_context(errors::ApiErrorResponse::InternalServerError)?- .clone(),- false,- )- .change_context(errors::ApiErrorResponse::InternalServerError)- .attach_printable("failed to decrypt google pay token")?;- let google_pay_data =- common_types::payments::GPayPredecryptData::from(google_pay_data_internal);+ .await?;Ok(PaymentMethodToken::GooglePayDecrypt(Box::new(google_pay_data,)))}}+/// Shared by the confirm flow (`WalletFlow::decrypt_wallet_token`) and the eligibility check.+async fn decrypt_apple_pay_wallet_data(+ payment_processing_details: &payments_api::PaymentProcessingDetails,+ apple_pay_wallet_data: &domain::ApplePayWalletData,+) -> CustomResult<common_types::payments::ApplePayPredecryptData, errors::ApiErrorResponse> {+ let apple_pay_data =+ ApplePayData::token_json(domain::WalletData::ApplePay(apple_pay_wallet_data.clone()))+ .change_context(errors::ApiErrorResponse::InternalServerError)+ .attach_printable("failed to parse apple pay token to json")?+ .decrypt(+ &payment_processing_details.payment_processing_certificate,+ &payment_processing_details.payment_processing_certificate_key,+ )+ .await+ .change_context(errors::ApiErrorResponse::InternalServerError)+ .attach_printable("failed to decrypt apple pay token")?;++ let apple_pay_predecrypt_internal = apple_pay_data+ .parse_value::<hyperswitch_domain_models::router_data::ApplePayPredecryptDataInternal>(+ "ApplePayPredecryptDataInternal",+ )+ .change_context(errors::ApiErrorResponse::InternalServerError)+ .attach_printable(+ "failed to parse decrypted apple pay response to ApplePayPredecryptData",+ )?;++ common_types::payments::ApplePayPredecryptData::try_from(apple_pay_predecrypt_internal)+ .change_context(errors::ApiErrorResponse::InternalServerError)+ .attach_printable(+ "failed to convert ApplePayPredecryptDataInternal to ApplePayPredecryptData",+ )+}++/// Shared by the confirm flow (`WalletFlow::decrypt_wallet_token`) and the eligibility check.+async fn decrypt_google_pay_wallet_data(+ payment_processing_details: &GooglePayPaymentProcessingDetails,+ google_pay_wallet_data: &domain::GooglePayWalletData,+) -> CustomResult<common_types::payments::GPayPredecryptData, errors::ApiErrorResponse> {+ let decryptor = helpers::GooglePayTokenDecryptor::new(+ payment_processing_details+ .google_pay_root_signing_keys+ .clone(),+ payment_processing_details.google_pay_recipient_id.clone(),+ payment_processing_details.google_pay_private_key.clone(),+ )+ .change_context(errors::ApiErrorResponse::InternalServerError)+ .attach_printable("failed to create google pay token decryptor")?;++ // should_verify_token is set to false to disable verification of token+ let google_pay_data_internal = decryptor+ .decrypt_token(+ google_pay_wallet_data+ .tokenization_data+ .get_encrypted_google_pay_token()+ .change_context(errors::ApiErrorResponse::InternalServerError)?+ .clone(),+ false,+ )+ .change_context(errors::ApiErrorResponse::InternalServerError)+ .attach_printable("failed to decrypt google pay token")?;+ Ok(common_types::payments::GPayPredecryptData::from(+ google_pay_data_internal,+ ))+}+#[derive(Debug, Clone)]pub enum DecideWalletFlow {ApplePayDecrypt(payments_api::PaymentProcessingDetails),@@ -9623,12 +9643,140 @@ wherepub update_request_fields: Option<PaymentDataUpdateRequestFields>,}+/// Decrypts an Apple Pay wallet token for the pre-confirm eligibility check, using the specific+/// merchant connector account (MCA) that generated the wallet's session token. Fails open+/// (`Ok(None)`) when the MCA or its decrypt certificates can't be resolved; a genuine decrypt+/// failure (bad cert/key) still propagates as an `Err`.+#[cfg(feature = "v1")]+async fn decrypt_apple_pay_wallet_for_eligibility(+ state: &SessionState,+ processor: &domain::Processor,+ merchant_connector_id: &id_type::MerchantConnectorAccountId,+ apple_pay_wallet_data: &domain::ApplePayWalletData,+) -> RouterResult<Option<domain::EligibilityPaymentMethodData>> {+ let payment_processing_details = state+ .store+ .find_by_merchant_connector_account_merchant_id_merchant_connector_id(+ processor.get_account().get_id(),+ merchant_connector_id,+ processor.get_key_store(),+ )+ .await+ .inspect_err(|error| {+ logger::warn!(+ ?error,+ merchant_connector_id = merchant_connector_id.get_string_repr(),+ "failed to fetch the merchant connector account for Apple Pay eligibility decryption"+ )+ })+ .ok()+ .map(|merchant_connector_account| {+ helpers::MerchantConnectorAccountType::DbVal(Box::new(merchant_connector_account))+ })+ .and_then(|merchant_connector_account| {+ check_apple_pay_metadata(state, Some(&merchant_connector_account))+ .and_then(|apple_pay_flow| match apple_pay_flow {+ domain::ApplePayFlow::DecryptAtApplication(payment_processing_details) => {+ Some(payment_processing_details)+ }+ domain::ApplePayFlow::SkipDecryption => None,+ })+ .or_else(|| {+ logger::warn!(+ merchant_connector_id = merchant_connector_id.get_string_repr(),+ "Apple Pay decrypt-at-application not configured for this connector account; skipping eligibility decryption"+ );+ None+ })+ });++ match payment_processing_details {+ Some(payment_processing_details) => {+ let apple_pay_predecrypt =+ decrypt_apple_pay_wallet_data(&payment_processing_details, apple_pay_wallet_data)+ .await?;++ Ok(Some(domain::EligibilityPaymentMethodData::Wallet(+ domain::WalletData::ApplePay(domain::ApplePayWalletData {+ payment_data: common_types::payments::ApplePayPaymentData::Decrypted(+ apple_pay_predecrypt,+ ),+ ..apple_pay_wallet_data.clone()+ }),+ )))+ }+ None => Ok(None),+ }+}++/// Decrypts a Google Pay wallet token for the pre-confirm eligibility check, using the specific+/// merchant connector account (MCA) that generated the wallet's session token. Fails open+/// (`Ok(None)`) when the MCA or its decrypt keys can't be resolved; a genuine decrypt failure+/// (bad key) still propagates as an `Err`.+#[cfg(feature = "v1")]+async fn decrypt_google_pay_wallet_for_eligibility(+ state: &SessionState,+ processor: &domain::Processor,+ merchant_connector_id: &id_type::MerchantConnectorAccountId,+ google_pay_wallet_data: &domain::GooglePayWalletData,+) -> RouterResult<Option<domain::EligibilityPaymentMethodData>> {+ let payment_processing_details = state+ .store+ .find_by_merchant_connector_account_merchant_id_merchant_connector_id(+ processor.get_account().get_id(),+ merchant_connector_id,+ processor.get_key_store(),+ )+ .await+ .inspect_err(|error| {+ logger::warn!(+ ?error,+ merchant_connector_id = merchant_connector_id.get_string_repr(),+ "failed to fetch the merchant connector account for Google Pay eligibility decryption"+ )+ })+ .ok()+ .map(|merchant_connector_account| {+ helpers::MerchantConnectorAccountType::DbVal(Box::new(merchant_connector_account))+ })+ .and_then(|merchant_connector_account| {+ get_google_pay_connector_wallet_details(state, &merchant_connector_account).or_else(+ || {+ logger::warn!(+ merchant_connector_id = merchant_connector_id.get_string_repr(),+ "Google Pay decrypt keys not configured for this connector account; skipping eligibility decryption"+ );+ None+ },+ )+ });++ match payment_processing_details {+ Some(payment_processing_details) => {+ let google_pay_predecrypt =+ decrypt_google_pay_wallet_data(&payment_processing_details, google_pay_wallet_data)+ .await?;++ Ok(Some(domain::EligibilityPaymentMethodData::Wallet(+ domain::WalletData::GooglePay(domain::GooglePayWalletData {+ tokenization_data: common_types::payments::GpayTokenizationData::Decrypted(+ google_pay_predecrypt,+ ),+ ..google_pay_wallet_data.clone()+ }),+ )))+ }+ None => Ok(None),+ }+}+#[cfg(feature = "v1")]#[derive(Clone)]pub struct PaymentEligibilityData {pub payment_method_data: Option<domain::EligibilityPaymentMethodData>,pub payment_intent: storage::PaymentIntent,pub browser_info: Option<pii::SecretSerdeValue>,+ pub merchant_connector_id: Option<id_type::MerchantConnectorAccountId>,}#[cfg(feature = "v1")]@@ -9690,13 +9838,99 @@ impl PaymentEligibilityData {.transpose()?.map(pii::SecretSerdeValue::new);+ let wallet_payment_method_type = match &payment_method_data {+ Some(domain::EligibilityPaymentMethodData::Wallet(domain::WalletData::GooglePay(+ google_pay_data,+ ))) if google_pay_data+ .tokenization_data+ .get_decrypted_google_pay_payment_data_optional()+ .is_none() =>+ {+ Some(storage_enums::PaymentMethodType::GooglePay)+ }+ Some(domain::EligibilityPaymentMethodData::Wallet(domain::WalletData::ApplePay(+ apple_pay_data,+ ))) if apple_pay_data+ .payment_data+ .get_decrypted_apple_pay_payment_data_optional()+ .is_none() =>+ {+ Some(storage_enums::PaymentMethodType::ApplePay)+ }+ _ => None,+ };++ let merchant_connector_id = match wallet_payment_method_type {+ Some(payment_method_type) => {+ Self::resolve_wallet_merchant_connector_id_from_pre_routing(+ state,+ platform,+ &payment_intent,+ payment_method_type,+ )+ .await?+ }+ None => None,+ };+Ok(Self {payment_method_data,browser_info,payment_intent,+ merchant_connector_id,})}+ /// Reads the MCA that will decrypt the wallet token from `pre_routing_results`, written to+ /// the attempt by `list_payment_methods`. `None` when pre-routing has not run: callers fail+ /// open rather than block.+ async fn resolve_wallet_merchant_connector_id_from_pre_routing(+ state: &SessionState,+ platform: &domain::Platform,+ payment_intent: &storage::PaymentIntent,+ payment_method_type: storage_enums::PaymentMethodType,+ ) -> CustomResult<Option<id_type::MerchantConnectorAccountId>, errors::ApiErrorResponse> {+ let payment_attempt = state+ .store+ .find_payment_attempt_by_payment_id_processor_merchant_id_attempt_id(+ &payment_intent.payment_id,+ &payment_intent.processor_merchant_id,+ &payment_intent.active_attempt.get_id(),+ platform.get_processor().get_account().storage_scheme,+ platform.get_processor().get_key_store(),+ )+ .await+ .to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)+ .attach_printable(+ "Error while fetching the payment attempt to resolve the wallet pre-routing connector",+ )?;++ Ok(payment_attempt+ .straight_through_algorithm+ .and_then(|straight_through_algorithm| {+ straight_through_algorithm+ .parse_value::<storage::PaymentRoutingInfo>("PaymentRoutingInfo")+ .inspect_err(|error| {+ logger::warn!(+ ?error,+ "failed to parse straight_through_algorithm as PaymentRoutingInfo for eligibility check"+ )+ })+ .ok()+ })+ .and_then(|routing_info| routing_info.pre_routing_results)+ .and_then(|mut pre_routing_results| pre_routing_results.remove(&payment_method_type))+ .and_then(|pre_routing_choice| match pre_routing_choice {+ storage::PreRoutingConnectorChoice::Single(routable_connector) => {+ Some(routable_connector)+ }+ storage::PreRoutingConnectorChoice::Multiple(routable_connector_list) => {+ routable_connector_list.into_iter().next()+ }+ })+ .and_then(|routable_connector| routable_connector.merchant_connector_id))+ }+/// Resolves a `payment_token` to raw card data for blocklist checks: modular/// organizations fetch from the PM Modular Service directly; legacy organizations/// resolve the Redis token to the payment method DB record, escalating to the@@ -13522,10 +13756,57 @@ impl EligibilityCheck for BlockListCheck {payment_elgibility_data: &PaymentEligibilityData,business_profile: &domain::Profile,) -> CustomResult<CheckResult, errors::ApiErrorResponse> {+ // Decrypt first so the blocklist runs against the DPAN. On skip (no MCA, keys not+ // configured) we fall back to the encrypted data, which yields no probes.+ let decrypted_payment_method_data = match (+ &payment_elgibility_data.payment_method_data,+ payment_elgibility_data.merchant_connector_id.as_ref(),+ ) {+ (+ Some(domain::EligibilityPaymentMethodData::Wallet(domain::WalletData::GooglePay(+ google_pay_data,+ ))),+ Some(merchant_connector_id),+ ) if google_pay_data+ .tokenization_data+ .get_decrypted_google_pay_payment_data_optional()+ .is_none() =>+ {+ decrypt_google_pay_wallet_for_eligibility(+ state,+ platform.get_processor(),+ merchant_connector_id,+ google_pay_data,+ )+ .await?+ }+ (+ Some(domain::EligibilityPaymentMethodData::Wallet(domain::WalletData::ApplePay(+ apple_pay_data,+ ))),+ Some(merchant_connector_id),+ ) if apple_pay_data+ .payment_data+ .get_decrypted_apple_pay_payment_data_optional()+ .is_none() =>+ {+ decrypt_apple_pay_wallet_for_eligibility(+ state,+ platform.get_processor(),+ merchant_connector_id,+ apple_pay_data,+ )+ .await?+ }+ _ => None,+ };+ let payment_method_data = decrypted_payment_method_data+ .or_else(|| payment_elgibility_data.payment_method_data.clone());+let block_reason = blocklist_utils::should_payment_be_blocked(state,platform.get_processor(),- &payment_elgibility_data.payment_method_data,+ &payment_method_data,business_profile,).await?;diff --git a/crates/router/src/core/payments/flows/session_flow.rs b/crates/router/src/core/payments/flows/session_flow.rsindex 02aa52a127..408fe8336b 100644--- a/crates/router/src/core/payments/flows/session_flow.rs+++ b/crates/router/src/core/payments/flows/session_flow.rs@@ -18,6 +18,7 @@ use super::{ConstructFlowSpecificData, Feature};use crate::{consts::PROTOCOL,core::{+ configs::dimension_state,errors::{self, ConnectorErrorExt, RouterResult},payments::{self, access_token, customers,@@ -270,6 +271,8 @@ async fn create_applepay_session_token(header_payload: hyperswitch_domain_models::payments::HeaderPayload,) -> RouterResult<types::PaymentsSessionRouterData> {let delayed_response = is_session_response_delayed(state, connector);+ let apple_pay_next_action =+ resolve_wallet_eligibility_next_action(state, router_data, business_profile).await;if delayed_response {let delayed_response_apple_pay_session =Some(payment_types::ApplePaySessionResponse::NoSessionResponse(@@ -281,7 +284,7 @@ async fn create_applepay_session_token(None, // Apple pay payment request will be none for delayed session responseconnector.connector_name.to_string(),delayed_response,- payment_types::NextActionCall::Confirm,+ apple_pay_next_action,header_payload,)} else {@@ -607,7 +610,7 @@ async fn create_applepay_session_token(Some(applepay_payment_request),connector.connector_name.to_string(),delayed_response,- payment_types::NextActionCall::Confirm,+ apple_pay_next_action,header_payload,)}@@ -912,7 +915,7 @@ fn apply_wallet_blocking_to_apple_pay_capabilities(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() {+ if wallet_config.is_credit_blocked_for_apple_pay() {capabilities.push("supportsDebit".to_string());}}@@ -923,7 +926,7 @@ 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() {+ if wallet_config.is_credit_blocked_for_google_pay() {Some(false)} else {None@@ -1005,7 +1008,37 @@ fn create_apple_pay_session_response(}}-fn create_gpay_session_token(+/// Whether the SDK should call eligiblity check for this wallet.+async fn resolve_wallet_eligibility_next_action(+ state: &routes::SessionState,+ router_data: &types::PaymentsSessionRouterData,+ business_profile: &domain::Profile,+) -> payment_types::NextActionCall {+ let dimensions = dimension_state::Dimensions::new()+ .with_processor_merchant_id(business_profile.merchant_id.clone().into())+ .with_provider_merchant_id(+ hyperswitch_domain_models::platform::ProviderMerchantId::new(+ business_profile.merchant_id.clone(),+ ),+ )+ .with_profile_id(business_profile.get_id().clone());++ let should_perform_eligibility = dimensions+ .get_should_perform_eligibility(+ state.store.as_ref(),+ state.superposition_service.as_ref(),+ router_data.customer_id.as_ref(),+ )+ .await;++ if should_perform_eligibility {+ payment_types::NextActionCall::EligibilityCheck+ } else {+ payment_types::NextActionCall::Confirm+ }+}++async fn create_gpay_session_token(state: &routes::SessionState,router_data: &types::PaymentsSessionRouterData,connector: &api::ConnectorData,@@ -1032,6 +1065,8 @@ fn create_gpay_session_token(.and_then(|connector_wallets_details| connector_wallets_details.google_pay);let connector_metadata = router_data.connector_meta_data.clone();let delayed_response = is_session_response_delayed(state, connector);+ let google_pay_next_action =+ resolve_wallet_eligibility_next_action(state, router_data, business_profile).await;if delayed_response {Ok(types::PaymentsSessionRouterData {@@ -1042,7 +1077,7 @@ fn create_gpay_session_token(delayed_session_token: true,connector: connector.connector_name.to_string(),sdk_next_action: payment_types::SdkNextAction {- next_action: payment_types::NextActionCall::Confirm,+ next_action: google_pay_next_action.clone(),should_block_confirm: None,},},@@ -1134,7 +1169,7 @@ fn create_gpay_session_token(transaction_info,connector: connector.connector_name.to_string(),sdk_next_action: payment_types::SdkNextAction {- next_action: payment_types::NextActionCall::Confirm,+ next_action: google_pay_next_action.clone(),should_block_confirm: None,},delayed_session_token: false,@@ -1236,7 +1271,7 @@ fn create_gpay_session_token(transaction_info,connector: connector.connector_name.to_string(),sdk_next_action: payment_types::SdkNextAction {- next_action: payment_types::NextActionCall::Confirm,+ next_action: google_pay_next_action,should_block_confirm: None,},delayed_session_token: false,@@ -1587,7 +1622,7 @@ impl RouterDataSession for types::PaymentsSessionRouterData {) -> RouterResult<Self> {match connector.get_token {api::GetToken::GpayMetadata => {- create_gpay_session_token(state, self, connector, business_profile)+ create_gpay_session_token(state, self, connector, business_profile).await}api::GetToken::SamsungPayMetadata => create_samsung_pay_session_token(state,