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(authentication): added cardbin/extended_cardbin routing support for exemption manager (#13577)

Sahkal Poddarfe7ccaa8c28e
diff --git a/api-reference/v1/openapi_spec_v1.json b/api-reference/v1/openapi_spec_v1.json
index e3942e1d2c..9a0aad94a5 100644
--- a/api-reference/v1/openapi_spec_v1.json
+++ b/api-reference/v1/openapi_spec_v1.json
@@ -28734,6 +28734,16 @@
"currency": {
"$ref": "#/components/schemas/Currency"
},
+ "card_bin": {
+ "type": "string",
+ "description": "The first 6 digits of the card number.",
+ "nullable": true
+ },
+ "extended_card_bin": {
+ "type": "string",
+ "description": "The first 8 digits of the card number.",
+ "nullable": true
+ },
"business_country": {
"allOf": [
{
@@ -43963,6 +43973,7 @@
"no_three_ds",
"challenge_requested",
"challenge_preferred",
+ "no_preference",
"three_ds_exemption_requested_tra",
"three_ds_exemption_requested_low_value",
"issuer_three_ds_exemption_requested"
diff --git a/api-reference/v2/openapi_spec_v2.json b/api-reference/v2/openapi_spec_v2.json
index 3aba11f495..7093d570ed 100644
--- a/api-reference/v2/openapi_spec_v2.json
+++ b/api-reference/v2/openapi_spec_v2.json
@@ -32118,6 +32118,7 @@
"no_three_ds",
"challenge_requested",
"challenge_preferred",
+ "no_preference",
"three_ds_exemption_requested_tra",
"three_ds_exemption_requested_low_value",
"issuer_three_ds_exemption_requested"
diff --git a/crates/api_models/src/three_ds_decision_rule.rs b/crates/api_models/src/three_ds_decision_rule.rs
index 124986b8eb..dd2fd73547 100644
--- a/crates/api_models/src/three_ds_decision_rule.rs
+++ b/crates/api_models/src/three_ds_decision_rule.rs
@@ -12,6 +12,10 @@ pub struct PaymentData {
/// The currency of the payment.
#[schema(value_type = Currency)]
pub currency: common_enums::Currency,
+ /// The first 6 digits of the card number.
+ pub card_bin: Option<String>,
+ /// The first 8 digits of the card number.
+ pub extended_card_bin: Option<String>,
/// The business country of the payment.
#[schema(value_type = Option<Country>)]
pub business_country: Option<common_enums::Country>,
diff --git a/crates/common_types/src/three_ds_decision_rule_engine.rs b/crates/common_types/src/three_ds_decision_rule_engine.rs
index 45f6b0b6fe..cd20036295 100644
--- a/crates/common_types/src/three_ds_decision_rule_engine.rs
+++ b/crates/common_types/src/three_ds_decision_rule_engine.rs
@@ -28,6 +28,8 @@ pub enum ThreeDSDecision {
ChallengeRequested,
/// Prefer 3DS Challenge
ChallengePreferred,
+ /// Perform 3DS authentication without expressing a challenge preference
+ NoPreference,
/// Request 3DS Exemption, Type: Transaction Risk Analysis (TRA)
ThreeDsExemptionRequestedTra,
/// Request 3DS Exemption, Type: Low Value Transaction
@@ -65,6 +67,8 @@ impl_to_sql_from_sql_json!(ThreeDSDecisionRule);
impl EuclidDirFilter for ThreeDSDecisionRule {
const ALLOWED: &'static [DirKeyKind] = &[
+ DirKeyKind::CardBin,
+ DirKeyKind::ExtendedCardBin,
DirKeyKind::CardNetwork,
DirKeyKind::PaymentAmount,
DirKeyKind::PaymentCurrency,
@@ -80,3 +84,25 @@ impl EuclidDirFilter for ThreeDSDecisionRule {
DirKeyKind::MetaData,
];
}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn no_preference_does_not_force_a_challenge() {
+ assert!(!ThreeDSDecision::NoPreference.should_force_3ds_challenge());
+ assert_eq!(
+ serde_json::to_value(ThreeDSDecision::NoPreference).expect("serialize decision"),
+ serde_json::json!("no_preference")
+ );
+ }
+
+ #[test]
+ fn bin_keys_are_allowed_for_three_ds_decision_rules() {
+ let allowed = <ThreeDSDecisionRule as EuclidDirFilter>::ALLOWED;
+
+ assert!(allowed.contains(&DirKeyKind::CardBin));
+ assert!(allowed.contains(&DirKeyKind::ExtendedCardBin));
+ }
+}
diff --git a/crates/hyperswitch_domain_models/src/payment_method_data.rs b/crates/hyperswitch_domain_models/src/payment_method_data.rs
index f651c0afd6..94c1ff9835 100644
--- a/crates/hyperswitch_domain_models/src/payment_method_data.rs
+++ b/crates/hyperswitch_domain_models/src/payment_method_data.rs
@@ -230,6 +230,22 @@ impl PaymentMethodData {
}
}
+ /// Extended BIN for any variant that carries the original card number.
+ pub fn get_card_extended_bin(&self) -> Option<String> {
+ match self {
+ Self::Card(card) => Some(card.card_number.get_extended_card_bin()),
+ Self::CardWithOptionalCVC(card) => Some(card.card_number.get_extended_card_bin()),
+ Self::CardWithNetworkTokenDetails(card) => {
+ Some(card.card_details.card_number.get_extended_card_bin())
+ }
+ Self::CardDetailsForNetworkTransactionId(card) => {
+ Some(card.card_number.get_extended_card_bin())
+ }
+ Self::CardWithLimitedDetails(card) => Some(card.card_number.get_extended_card_bin()),
+ _ => None,
+ }
+ }
+
pub fn apply_additional_payment_data(
&self,
additional_payment_data: api_models::payments::AdditionalPaymentData,
diff --git a/crates/router/src/consts.rs b/crates/router/src/consts.rs
index 1f0d24f48a..15042ddb1b 100644
--- a/crates/router/src/consts.rs
+++ b/crates/router/src/consts.rs
@@ -308,8 +308,9 @@ pub const IRRELEVANT_CONNECTOR_REQUEST_REFERENCE_ID: &str =
// Default payment method storing TTL in redis in seconds
pub const DEFAULT_PAYMENT_METHOD_STORE_TTL: i64 = 86400; // 1 day
-// List of countries that are part of the PSD2 region
-pub const PSD2_COUNTRIES: [Country; 27] = [
+// Countries and separately encoded territories where PSD2 or the equivalent UK
+// strong customer authentication rules apply.
+pub const SCA_MANDATED_COUNTRIES: [Country; 39] = [
Country::Austria,
Country::Belgium,
Country::Bulgaria,
@@ -337,6 +338,21 @@ pub const PSD2_COUNTRIES: [Country; 27] = [
Country::Slovenia,
Country::Spain,
Country::Sweden,
+ // EEA/EFTA states where PSD2 applies
+ Country::Iceland,
+ Country::Liechtenstein,
+ Country::Norway,
+ // EU territories represented separately by the Country enum
+ Country::AlandIslands,
+ Country::FrenchGuiana,
+ Country::Guadeloupe,
+ Country::Martinique,
+ Country::Mayotte,
+ Country::Reunion,
+ Country::SaintMartinFrenchpart,
+ // Jurisdictions covered by the equivalent UK SCA regime
+ Country::UnitedKingdomOfGreatBritainAndNorthernIreland,
+ Country::Gibraltar,
];
// Rollout percentage config prefix
diff --git a/crates/router/src/core/payments/operations/payment_confirm.rs b/crates/router/src/core/payments/operations/payment_confirm.rs
index 61713347d1..2dd21c8b1c 100644
--- a/crates/router/src/core/payments/operations/payment_confirm.rs
+++ b/crates/router/src/core/payments/operations/payment_confirm.rs
@@ -1698,6 +1698,26 @@ impl<F: Clone + Send + Sync> Domain<F, api::PaymentsRequest, PaymentData<F>> for
.inspect_err(|err| logger::error!("{:?}", err))
.ok()
.unwrap_or_default(),
+ card_bin: payment_data
+ .payment_method_data
+ .as_ref()
+ .and_then(|payment_method_data| payment_method_data.get_card_iin())
+ .or_else(|| {
+ additional_card_info
+ .as_ref()
+ .and_then(|card_info| card_info.card_isin.clone())
+ }),
+ extended_card_bin: payment_data
+ .payment_method_data
+ .as_ref()
+ .and_then(|payment_method_data| {
+ payment_method_data.get_card_extended_bin()
+ })
+ .or_else(|| {
+ additional_card_info
+ .as_ref()
+ .and_then(|card_info| card_info.card_extended_bin.clone())
+ }),
business_country: payment_data
.payment_intent
.business_country
diff --git a/crates/router/src/core/payments/transformers.rs b/crates/router/src/core/payments/transformers.rs
index be7d864bfa..703080581f 100644
--- a/crates/router/src/core/payments/transformers.rs
+++ b/crates/router/src/core/payments/transformers.rs
@@ -8016,6 +8016,7 @@ impl ForeignFrom<common_types::three_ds_decision_rule_engine::ThreeDSDecision>
common_types::three_ds_decision_rule_engine::ThreeDSDecision::NoThreeDs => Self::NoThreeDs,
common_types::three_ds_decision_rule_engine::ThreeDSDecision::ChallengeRequested
| common_types::three_ds_decision_rule_engine::ThreeDSDecision::ChallengePreferred
+ | common_types::three_ds_decision_rule_engine::ThreeDSDecision::NoPreference
| common_types::three_ds_decision_rule_engine::ThreeDSDecision::ThreeDsExemptionRequestedTra
| common_types::three_ds_decision_rule_engine::ThreeDSDecision::ThreeDsExemptionRequestedLowValue
| common_types::three_ds_decision_rule_engine::ThreeDSDecision::IssuerThreeDsExemptionRequested => Self::ThreeDs,
@@ -8039,6 +8040,7 @@ impl ForeignFrom<common_types::three_ds_decision_rule_engine::ThreeDSDecision>
common_types::three_ds_decision_rule_engine::ThreeDSDecision::NoThreeDs
| common_types::three_ds_decision_rule_engine::ThreeDSDecision::ChallengeRequested
| common_types::three_ds_decision_rule_engine::ThreeDSDecision::ChallengePreferred
+ | common_types::three_ds_decision_rule_engine::ThreeDSDecision::NoPreference
| common_types::three_ds_decision_rule_engine::ThreeDSDecision::IssuerThreeDsExemptionRequested => {
None
}
diff --git a/crates/router/src/core/three_ds_decision_rule.rs b/crates/router/src/core/three_ds_decision_rule.rs
index e669eb7e1b..f0bd18d0ec 100644
--- a/crates/router/src/core/three_ds_decision_rule.rs
+++ b/crates/router/src/core/three_ds_decision_rule.rs
@@ -8,7 +8,7 @@ use euclid::{
frontend::ast,
};
use hyperswitch_domain_models::platform::Platform;
-use router_env::{instrument, tracing};
+use router_env::{instrument, logger, tracing};
use crate::{
core::{
@@ -73,9 +73,14 @@ pub async fn get_three_ds_decision_rule_output(
.execute(backend_input)
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Error executing 3DS decision rule")?;
- // Apply PSD2 validations to the decision
+
+ logger::info!(
+ "3DS decision after rule evaluation {:?}",
+ result.get_output().get_decision()
+ );
+ // Apply SCA validations to the decision
let final_decision =
- utils::apply_psd2_validations_during_execute(result.get_output().get_decision(), &request);
+ utils::apply_sca_validations_during_execute(result.get_output().get_decision(), &request);
Ok(final_decision)
}
diff --git a/crates/router/src/core/three_ds_decision_rule/utils.rs b/crates/router/src/core/three_ds_decision_rule/utils.rs
index f3901ba046..78fe7350d0 100644
--- a/crates/router/src/core/three_ds_decision_rule/utils.rs
+++ b/crates/router/src/core/three_ds_decision_rule/utils.rs
@@ -2,37 +2,50 @@ use api_models::three_ds_decision_rule as api_threedsecure;
use common_types::three_ds_decision_rule_engine::ThreeDSDecision;
use euclid::backend::inputs as dsl_inputs;
-use crate::{consts::PSD2_COUNTRIES, types::transformers::ForeignFrom};
+use crate::{consts::SCA_MANDATED_COUNTRIES, types::transformers::ForeignFrom};
-// function to apply PSD2 validations to the decision
-pub fn apply_psd2_validations_during_execute(
+// Apply SCA validations to the decision for regulated issuer/acquirer combinations.
+pub fn apply_sca_validations_during_execute(
decision: ThreeDSDecision,
request: &api_models::three_ds_decision_rule::ThreeDsDecisionRuleExecuteRequest,
) -> ThreeDSDecision {
- let issuer_in_psd2 = request
+ let issuer_in_sca_mandated_country = request
.issuer
.as_ref()
.and_then(|issuer| issuer.country)
- .map(|country| PSD2_COUNTRIES.contains(&country))
+ .map(|country| SCA_MANDATED_COUNTRIES.contains(&country))
.unwrap_or(false);
- let acquirer_in_psd2 = request
+ let acquirer_in_sca_mandated_country = request
.acquirer
.as_ref()
.and_then(|acquirer| acquirer.country)
- .map(|country| PSD2_COUNTRIES.contains(&country))
+ .map(|country| SCA_MANDATED_COUNTRIES.contains(&country))
.unwrap_or(false);
- if issuer_in_psd2 && acquirer_in_psd2 {
- // If both issuer and acquirer are in PSD2 region
+ apply_sca_validations_to_decision(
+ decision,
+ issuer_in_sca_mandated_country && acquirer_in_sca_mandated_country,
+ )
+}
+
+fn apply_sca_validations_to_decision(
+ decision: ThreeDSDecision,
+ sca_mandate_applies: bool,
+) -> ThreeDSDecision {
+ if sca_mandate_applies {
+ // NoThreeDs is not allowed when both PSPs are in an SCA-mandated region.
match decision {
- // If the decision is to enforce no 3DS, override it to enforce 3DS
- ThreeDSDecision::NoThreeDs => ThreeDSDecision::ChallengeRequested,
+ // NoPreference requests 3DS without inventing an exemption preference.
+ ThreeDSDecision::NoThreeDs => ThreeDSDecision::NoPreference,
_ => decision,
}
} else {
- // If PSD2 doesn't apply, exemptions cannot be applied
+ // PSD2/UK SCA exemptions are not applicable outside regulated regions, but
+ // merchants may explicitly choose no 3DS there.
match decision {
ThreeDSDecision::NoThreeDs => ThreeDSDecision::NoThreeDs,
- // For all other decisions (including exemptions), enforce challenge as exemptions are only valid in PSD2 regions
+ ThreeDSDecision::NoPreference => ThreeDSDecision::NoPreference,
+ // Exemption and challenge-preference decisions are forced to a challenge outside
+ // PSD2. NoPreference is preserved because it does not request an exemption.
_ => ThreeDSDecision::ChallengeRequested,
}
}
@@ -50,8 +63,8 @@ impl ForeignFrom<api_threedsecure::PaymentData> for dsl_inputs::PaymentInput {
billing_country: None,
business_label: None,
setup_future_usage: None,
- card_bin: None,
- extended_card_bin: None,
+ card_bin: request_payment_data.card_bin,
+ extended_card_bin: request_payment_data.extended_card_bin,
surcharge_amount: None,
}
}