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
refactor(authentication): profile acquirer module to support multi network bin (#11736)
Sahkal Poddar94f542c036d5
diff --git a/api-reference/v1/openapi_spec_v1.json b/api-reference/v1/openapi_spec_v1.jsonindex 461c3dd6ae..32672e0be1 100644--- a/api-reference/v1/openapi_spec_v1.json+++ b/api-reference/v1/openapi_spec_v1.json@@ -8862,26 +8862,74 @@}}},+ "AcquirerBucketConfigResponse": {+ "type": "object",+ "required": [+ "network"+ ],+ "properties": {+ "acquirer_assigned_merchant_id": {+ "type": "string",+ "description": "The merchant id assigned by the acquirer",+ "example": "M123456789",+ "nullable": true+ },+ "merchant_name": {+ "type": "string",+ "description": "Merchant name",+ "example": "NewAge Retailer",+ "nullable": true+ },+ "network": {+ "type": "string",+ "description": "Network provider",+ "example": "VISA"+ },+ "acquirer_bin": {+ "type": "string",+ "description": "Acquirer bin",+ "example": "456789",+ "nullable": true+ },+ "acquirer_ica": {+ "type": "string",+ "description": "Acquirer ica provided by acquirer",+ "example": "401288",+ "nullable": true+ },+ "acquirer_fraud_rate": {+ "type": "number",+ "format": "double",+ "description": "Fraud rate for the particular acquirer configuration",+ "example": 0.01,+ "nullable": true+ },+ "acquirer_country_code": {+ "type": "string",+ "description": "Acquirer country code",+ "example": "US",+ "nullable": true+ }+ }+ },"AcquirerConfig": {"type": "object","description": "Acquirer configuration","required": [- "acquirer_assigned_merchant_id",- "merchant_name",- "network",- "acquirer_bin",- "acquirer_fraud_rate"+ "network"],"properties": {"acquirer_assigned_merchant_id": {"type": "string","description": "The merchant id assigned by the acquirer",- "example": "M123456789"+ "example": "M123456789",+ "nullable": true},"merchant_name": {"type": "string","description": "merchant name",- "example": "NewAge Retailer"+ "example": "NewAge Retailer",+ "nullable": true},"network": {"type": "string",@@ -8891,7 +8939,8 @@"acquirer_bin": {"type": "string","description": "Acquirer bin",- "example": "456789"+ "example": "456789",+ "nullable": true},"acquirer_ica": {"type": "string",@@ -8900,17 +8949,40 @@"nullable": true},"acquirer_fraud_rate": {- "type": "string",+ "type": "number",+ "format": "double","description": "Fraud rate for the particular acquirer configuration",- "example": "0.01"+ "example": 0.01,+ "nullable": true+ },+ "acquirer_country_code": {+ "type": "string",+ "description": "Acquirer country code",+ "example": "US",+ "nullable": true}}},- "AcquirerConfigMap": {+ "AcquirerConfigBucket": {"type": "object",- "description": "Acquirer configs",+ "description": "Acquirer config buckets: each ProfileAcquirerId maps to an array of per-network configs",+ "required": [+ "default_acquirer_config"+ ],+ "properties": {+ "default_acquirer_config": {+ "type": "string",+ "description": "The default acquirer config id",+ "example": "pro_acq_LCRdERuylQvNQ4qh3QE0"+ }+ },"additionalProperties": {- "$ref": "#/components/schemas/AcquirerConfig"+ "type": "array",+ "items": {+ "$ref": "#/components/schemas/AcquirerConfig"+ },+ "description": "Flattened map of acquirer profiles keyed by configuration id",+ "example": "{\n \"profile_acquirer_id\": \"profile_acquirer_id\",\n \"acquirer_config\": {\n \"acquirer_assigned_merchant_id\": \"M123456789\",\n \"merchant_name\": \"NewAge Retailer\",\n \"network\": \"VISA\",\n \"acquirer_bin\": \"456789\",\n \"acquirer_ica\": \"401288\",\n \"acquirer_fraud_rate\": 0.01,\n \"acquirer_country_code\": \"US\"\n }"}},"AcquirerData": {@@ -30698,6 +30770,11 @@}],"nullable": true+ },+ "profile_acquirer_id": {+ "type": "string",+ "description": "Identification for the profile acquirer to be used for this payment.",+ "nullable": true}}},@@ -31242,6 +31319,11 @@}],"nullable": true+ },+ "profile_acquirer_id": {+ "type": "string",+ "description": "Identification for the profile acquirer to be used for this payment.",+ "nullable": true}}},@@ -32904,6 +32986,11 @@}],"nullable": true+ },+ "profile_acquirer_id": {+ "type": "string",+ "description": "Identification for the profile acquirer to be used for this payment.",+ "nullable": true}},"additionalProperties": false@@ -34395,6 +34482,11 @@}],"nullable": true+ },+ "profile_acquirer_id": {+ "type": "string",+ "description": "Identification for the profile acquirer to be used for this payment.",+ "nullable": true}}},@@ -37021,6 +37113,30 @@"accommodation"]},+ "ProfileAcquirerConfigsResponse": {+ "type": "object",+ "required": [+ "configs"+ ],+ "properties": {+ "default_acquirer_config": {+ "type": "string",+ "description": "The default bucket for acquirer configurations",+ "example": "pro_acq_LCRdERuylQvNQ4qh3QE0",+ "nullable": true+ },+ "configs": {+ "type": "object",+ "description": "Flattened map of acquirer configuration buckets",+ "additionalProperties": {+ "type": "array",+ "items": {+ "$ref": "#/components/schemas/AcquirerBucketConfigResponse"+ }+ }+ }+ }+ },"ProfileAcquirerCreate": {"type": "object","required": [@@ -37028,7 +37144,6 @@"merchant_name","network","acquirer_bin",- "acquirer_fraud_rate","profile_id"],"properties": {@@ -37062,25 +37177,37 @@"type": "number","format": "double","description": "Fraud rate for the particular acquirer configuration",- "example": 0.01+ "example": 0.01,+ "nullable": true+ },+ "acquirer_country_code": {+ "type": "string",+ "description": "Acquirer country code",+ "example": "US",+ "nullable": true},"profile_id": {"type": "string","description": "Parent profile id to link the acquirer account with","example": "pro_ky0yNyOXXlA5hF8JzE5q"+ },+ "is_default": {+ "type": "boolean",+ "description": "Whether this configuration bucket is the default fallback for the profile.",+ "nullable": true}}},+ "ProfileAcquirerId": {+ "type": "string",+ "description": "A type for profile_acquirer_id that can be used for profile acquirer ids"+ },"ProfileAcquirerResponse": {"type": "object","required": ["profile_acquirer_id",- "acquirer_assigned_merchant_id",- "merchant_name",- "network",- "acquirer_bin",- "acquirer_fraud_rate",- "profile_id"+ "profile_id",+ "is_default"],"properties": {"profile_acquirer_id": {@@ -37091,22 +37218,26 @@"acquirer_assigned_merchant_id": {"type": "string","description": "The merchant id assigned by the acquirer",- "example": "M123456789"+ "example": "M123456789",+ "nullable": true},"merchant_name": {"type": "string","description": "Merchant name",- "example": "NewAge Retailer"+ "example": "NewAge Retailer",+ "nullable": true},"network": {"type": "string","description": "Network provider",- "example": "VISA"+ "example": "VISA",+ "nullable": true},"acquirer_bin": {"type": "string","description": "Acquirer bin",- "example": "456789"+ "example": "456789",+ "nullable": true},"acquirer_ica": {"type": "string",@@ -37118,12 +37249,23 @@"type": "number","format": "double","description": "Fraud rate for the particular acquirer configuration",- "example": 0.01+ "example": 0.01,+ "nullable": true+ },+ "acquirer_country_code": {+ "type": "string",+ "description": "Acquirer country code",+ "example": "US",+ "nullable": true},"profile_id": {"type": "string","description": "Parent profile id to link the acquirer account with","example": "pro_ky0yNyOXXlA5hF8JzE5q"+ },+ "is_default": {+ "type": "boolean",+ "description": "Whether this configuration bucket is the default fallback for the profile."}}},@@ -37142,6 +37284,7 @@},"network": {"type": "string",+ "description": "The card network this configuration entry targets — optional if updating just the default.","example": "MASTERCARD","nullable": true},@@ -37160,6 +37303,16 @@"format": "double","example": "0.02","nullable": true+ },+ "acquirer_country_code": {+ "type": "string",+ "example": "US",+ "nullable": true+ },+ "is_default": {+ "type": "boolean",+ "description": "Whether this configuration bucket is the default fallback for the profile.",+ "nullable": true}},"additionalProperties": false@@ -37782,7 +37935,16 @@"items": {"$ref": "#/components/schemas/ProfileAcquirerResponse"},- "description": "Acquirer configs",+ "description": "Acquirer configs (Deprecated - use `acquirer_config_bucket` instead)",+ "deprecated": true,+ "nullable": true+ },+ "acquirer_config_bucket": {+ "allOf": [+ {+ "$ref": "#/components/schemas/ProfileAcquirerConfigsResponse"+ }+ ],"nullable": true},"is_iframe_redirection_enabled": {diff --git a/crates/api_models/src/admin.rs b/crates/api_models/src/admin.rsindex 70c4802b36..ad9a271163 100644--- a/crates/api_models/src/admin.rs+++ b/crates/api_models/src/admin.rs@@ -18,12 +18,12 @@ use smithy::SmithyModel;use utoipa::ToSchema;use super::payments::AddressDetails;+#[cfg(feature = "v1")]+use crate::routing;use crate::{consts::{MAX_ORDER_FULFILLMENT_EXPIRY, MIN_ORDER_FULFILLMENT_EXPIRY},- enums as api_enums, payment_methods,+ enums as api_enums, payment_methods, profile_acquirer,};-#[cfg(feature = "v1")]-use crate::{profile_acquirer::ProfileAcquirerResponse, routing};#[derive(Clone, Debug, Deserialize, ToSchema, Serialize)]pub struct MerchantAccountListRequest {@@ -2702,9 +2702,13 @@ pub struct ProfileResponse {#[schema(default = false, example = false)]pub is_pre_network_tokenization_enabled: bool,- /// Acquirer configs- #[schema(value_type = Option<Vec<ProfileAcquirerResponse>>)]- pub acquirer_configs: Option<Vec<ProfileAcquirerResponse>>,+ /// Acquirer configs (Deprecated - use `acquirer_config_bucket` instead)+ #[schema(value_type = Option<Vec<ProfileAcquirerResponse>>, deprecated)]+ pub acquirer_configs: Option<Vec<profile_acquirer::ProfileAcquirerResponse>>,++ /// Acquirer config buckets: map of acquirer profile configurations+ #[schema(value_type = Option<ProfileAcquirerConfigsResponse>)]+ pub acquirer_config_bucket: Option<profile_acquirer::ProfileAcquirerConfigsResponse>,/// Indicates if the redirection has to open in the iframe#[schema(example = false)]diff --git a/crates/api_models/src/payments.rs b/crates/api_models/src/payments.rsindex 380d9d6f0a..7f6f959287 100644--- a/crates/api_models/src/payments.rs+++ b/crates/api_models/src/payments.rs@@ -1591,6 +1591,10 @@ pub struct PaymentsRequest {/// Installment data selected by the customer during payment confirmation. This is used to specify the chosen number of installments and billing frequency.pub installment_data: Option<InstallmentRequest>,++ /// Identification for the profile acquirer to be used for this payment.+ #[schema(value_type = Option<String>)]+ pub profile_acquirer_id: Option<id_type::ProfileAcquirerId>,}#[derive(Clone, Debug, PartialEq, serde::Serialize, serde::Deserialize, ToSchema, SmithyModel)]diff --git a/crates/api_models/src/profile_acquirer.rs b/crates/api_models/src/profile_acquirer.rsindex 9689be7d99..2dabfa325e 100644--- a/crates/api_models/src/profile_acquirer.rs+++ b/crates/api_models/src/profile_acquirer.rs@@ -19,11 +19,16 @@ pub struct ProfileAcquirerCreate {#[schema(value_type= Option<String>,example = "401288")]pub acquirer_ica: Option<String>,/// Fraud rate for the particular acquirer configuration- #[schema(value_type= f64,example = 0.01)]- pub acquirer_fraud_rate: f64,+ #[schema(value_type= Option<f64>,example = 0.01)]+ pub acquirer_fraud_rate: Option<f64>,+ /// Acquirer country code+ #[schema(value_type= Option<String>,example = "US")]+ pub acquirer_country_code: Option<String>,/// Parent profile id to link the acquirer account with#[schema(value_type= String,example = "pro_ky0yNyOXXlA5hF8JzE5q")]pub profile_id: common_utils::id_type::ProfileId,+ /// Whether this configuration bucket is the default fallback for the profile.+ pub is_default: Option<bool>,}#[derive(Debug, Serialize, Deserialize, ToSchema, Clone)]@@ -32,54 +37,116 @@ pub struct ProfileAcquirerResponse {#[schema(value_type= String,example = "pro_acq_LCRdERuylQvNQ4qh3QE0")]pub profile_acquirer_id: common_utils::id_type::ProfileAcquirerId,/// The merchant id assigned by the acquirer- #[schema(value_type= String,example = "M123456789")]- pub acquirer_assigned_merchant_id: String,+ #[schema(value_type= Option<String>,example = "M123456789")]+ pub acquirer_assigned_merchant_id: Option<String>,/// Merchant name- #[schema(value_type= String,example = "NewAge Retailer")]- pub merchant_name: String,+ #[schema(value_type= Option<String>,example = "NewAge Retailer")]+ pub merchant_name: Option<String>,/// Network provider- #[schema(value_type= String,example = "VISA")]- pub network: common_enums::enums::CardNetwork,+ #[schema(value_type= Option<String>,example = "VISA")]+ pub network: Option<common_enums::enums::CardNetwork>,/// Acquirer bin- #[schema(value_type= String,example = "456789")]- pub acquirer_bin: String,+ #[schema(value_type= Option<String>,example = "456789")]+ pub acquirer_bin: Option<String>,/// Acquirer ica provided by acquirer#[schema(value_type= Option<String>,example = "401288")]pub acquirer_ica: Option<String>,/// Fraud rate for the particular acquirer configuration- #[schema(value_type= f64,example = 0.01)]- pub acquirer_fraud_rate: f64,+ #[schema(value_type= Option<f64>,example = 0.01)]+ pub acquirer_fraud_rate: Option<f64>,+ /// Acquirer country code+ #[schema(value_type= Option<String>,example = "US")]+ pub acquirer_country_code: Option<String>,/// Parent profile id to link the acquirer account with#[schema(value_type= String,example = "pro_ky0yNyOXXlA5hF8JzE5q")]pub profile_id: common_utils::id_type::ProfileId,+ /// Whether this configuration bucket is the default fallback for the profile.+ pub is_default: bool,+}++#[derive(Debug, Serialize, Deserialize, ToSchema, Clone)]+pub struct AcquirerBucketConfigResponse {+ /// The merchant id assigned by the acquirer+ #[schema(value_type= Option<String>,example = "M123456789")]+ pub acquirer_assigned_merchant_id: Option<String>,+ /// Merchant name+ #[schema(value_type= Option<String>,example = "NewAge Retailer")]+ pub merchant_name: Option<String>,+ /// Network provider+ #[schema(value_type= String,example = "VISA")]+ pub network: common_enums::enums::CardNetwork,+ /// Acquirer bin+ #[schema(value_type= Option<String>,example = "456789")]+ pub acquirer_bin: Option<String>,+ /// Acquirer ica provided by acquirer+ #[schema(value_type= Option<String>,example = "401288")]+ pub acquirer_ica: Option<String>,+ /// Fraud rate for the particular acquirer configuration+ #[schema(value_type= Option<f64>,example = 0.01)]+ pub acquirer_fraud_rate: Option<f64>,+ /// Acquirer country code+ #[schema(value_type= Option<String>,example = "US")]+ pub acquirer_country_code: Option<String>,}impl common_utils::events::ApiEventMetric for ProfileAcquirerCreate {}impl common_utils::events::ApiEventMetric for ProfileAcquirerResponse {}+impl common_utils::events::ApiEventMetric for AcquirerBucketConfigResponse {}++#[derive(Clone, Debug, serde::Serialize, utoipa::ToSchema)]+pub struct ProfileAcquirerConfigsResponse {+ /// The default bucket for acquirer configurations+ #[schema(value_type= Option<String>,example = "pro_acq_LCRdERuylQvNQ4qh3QE0")]+ pub default_acquirer_config: Option<common_utils::id_type::ProfileAcquirerId>,+ /// Flattened map of acquirer configuration buckets+ pub configs: std::collections::HashMap<+ common_utils::id_type::ProfileAcquirerId,+ Vec<AcquirerBucketConfigResponse>,+ >,+}implFrom<(common_utils::id_type::ProfileAcquirerId,&common_utils::id_type::ProfileId,- &common_types::domain::AcquirerConfig,+ Option<&common_types::domain::AcquirerConfig>,+ bool,)> for ProfileAcquirerResponse{fn from(- (profile_acquirer_id, profile_id, acquirer_config): (+ (profile_acquirer_id, profile_id, acquirer_config, is_default): (common_utils::id_type::ProfileAcquirerId,&common_utils::id_type::ProfileId,- &common_types::domain::AcquirerConfig,+ Option<&common_types::domain::AcquirerConfig>,+ bool,),) -> Self {Self {profile_acquirer_id,profile_id: profile_id.clone(),+ acquirer_assigned_merchant_id: acquirer_config+ .and_then(|c| c.acquirer_assigned_merchant_id.clone()),+ merchant_name: acquirer_config.and_then(|c| c.merchant_name.clone()),+ network: acquirer_config.map(|c| c.network.clone()),+ acquirer_bin: acquirer_config.and_then(|c| c.acquirer_bin.clone()),+ acquirer_ica: acquirer_config.and_then(|c| c.acquirer_ica.clone()),+ acquirer_fraud_rate: acquirer_config.and_then(|c| c.acquirer_fraud_rate),+ acquirer_country_code: acquirer_config.and_then(|c| c.acquirer_country_code.clone()),+ is_default,+ }+ }+}++impl From<&common_types::domain::AcquirerConfig> for AcquirerBucketConfigResponse {+ fn from(acquirer_config: &common_types::domain::AcquirerConfig) -> Self {+ Self {acquirer_assigned_merchant_id: acquirer_config.acquirer_assigned_merchant_id.clone(),merchant_name: acquirer_config.merchant_name.clone(),network: acquirer_config.network.clone(),acquirer_bin: acquirer_config.acquirer_bin.clone(),acquirer_ica: acquirer_config.acquirer_ica.clone(),acquirer_fraud_rate: acquirer_config.acquirer_fraud_rate,+ acquirer_country_code: acquirer_config.acquirer_country_code.clone(),}}}@@ -91,6 +158,7 @@ pub struct ProfileAcquirerUpdate {pub acquirer_assigned_merchant_id: Option<String>,#[schema(value_type = Option<String>, example = "Updated Retailer Name")]pub merchant_name: Option<String>,+ /// The card network this configuration entry targets — optional if updating just the default.#[schema(value_type = Option<String>, example = "MASTERCARD")]pub network: Option<common_enums::enums::CardNetwork>,#[schema(value_type = Option<String>, example = "987654")]@@ -99,6 +167,10 @@ pub struct ProfileAcquirerUpdate {pub acquirer_ica: Option<String>,#[schema(value_type = Option<f64>, example = "0.02")]pub acquirer_fraud_rate: Option<f64>,+ #[schema(value_type = Option<String>, example = "US")]+ pub acquirer_country_code: Option<String>,+ /// Whether this configuration bucket is the default fallback for the profile.+ pub is_default: Option<bool>,}impl common_utils::events::ApiEventMetric for ProfileAcquirerUpdate {}diff --git a/crates/common_types/src/domain.rs b/crates/common_types/src/domain.rsindex bb0c20fb6a..bacb17db18 100644--- a/crates/common_types/src/domain.rs+++ b/crates/common_types/src/domain.rs@@ -101,31 +101,52 @@ impl_to_sql_from_sql_json!(XenditSplitSubMerchantData);#[derive(Clone, Debug, Deserialize, ToSchema, Serialize, PartialEq)]pub struct AcquirerConfig {/// The merchant id assigned by the acquirer- #[schema(value_type= String,example = "M123456789")]- pub acquirer_assigned_merchant_id: String,+ #[schema(value_type= Option<String>,example = "M123456789")]+ pub acquirer_assigned_merchant_id: Option<String>,/// merchant name- #[schema(value_type= String,example = "NewAge Retailer")]- pub merchant_name: String,+ #[schema(value_type= Option<String>,example = "NewAge Retailer")]+ pub merchant_name: Option<String>,/// Network provider#[schema(value_type= String,example = "VISA")]pub network: common_enums::CardNetwork,/// Acquirer bin- #[schema(value_type= String,example = "456789")]- pub acquirer_bin: String,+ #[schema(value_type= Option<String>,example = "456789")]+ pub acquirer_bin: Option<String>,/// Acquirer ica provided by acquirer#[schema(value_type= Option<String>,example = "401288")]pub acquirer_ica: Option<String>,/// Fraud rate for the particular acquirer configuration- #[schema(value_type= String,example = "0.01")]- pub acquirer_fraud_rate: f64,+ #[schema(value_type= Option<f64>,example = 0.01)]+ pub acquirer_fraud_rate: Option<f64>,+ /// Acquirer country code+ #[schema(value_type= Option<String>,example = "US")]+ pub acquirer_country_code: Option<String>,}#[derive(Serialize, Deserialize, Debug, Clone, FromSqlRow, AsExpression, ToSchema)]#[diesel(sql_type = Jsonb)]-/// Acquirer configs-pub struct AcquirerConfigMap(pub HashMap<common_utils::id_type::ProfileAcquirerId, AcquirerConfig>);+/// Acquirer config buckets: each ProfileAcquirerId maps to an array of per-network configs+pub struct AcquirerConfigBucket {+ /// The default acquirer config id+ #[schema(value_type= String,example = "pro_acq_LCRdERuylQvNQ4qh3QE0")]+ pub default_acquirer_config: Option<common_utils::id_type::ProfileAcquirerId>,+ /// Flattened map of acquirer profiles keyed by configuration id+ #[serde(flatten)]+ #[schema(value_type= HashMap<String, Vec<AcquirerConfig>>, example = r#"{+ "profile_acquirer_id": "profile_acquirer_id",+ "acquirer_config": {+ "acquirer_assigned_merchant_id": "M123456789",+ "merchant_name": "NewAge Retailer",+ "network": "VISA",+ "acquirer_bin": "456789",+ "acquirer_ica": "401288",+ "acquirer_fraud_rate": 0.01,+ "acquirer_country_code": "US"+ }"#)]+ pub configs: HashMap<common_utils::id_type::ProfileAcquirerId, Vec<AcquirerConfig>>,+}-impl_to_sql_from_sql_json!(AcquirerConfigMap);+impl_to_sql_from_sql_json!(AcquirerConfigBucket);/// Merchant connector details#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, ToSchema)]diff --git a/crates/diesel_models/src/authentication.rs b/crates/diesel_models/src/authentication.rsindex 476fca694f..cd36de2ac5 100644--- a/crates/diesel_models/src/authentication.rs+++ b/crates/diesel_models/src/authentication.rs@@ -249,6 +249,12 @@ pub enum AuthenticationUpdate {trans_status: common_enums::TransactionStatus,authentication_status: common_enums::AuthenticationStatus,},+ /// Persists resolved acquirer details after bucket-based network lookup (eligibility_core)+ AcquirerDetailsUpdate {+ acquirer_bin: Option<String>,+ acquirer_merchant_id: Option<String>,+ acquirer_country_code: Option<String>,+ },}impl Default for AuthenticationUpdateInternal {@@ -705,6 +711,16 @@ impl From<AuthenticationUpdate> for AuthenticationUpdateInternal {authentication_status: Some(authentication_status),..Default::default()},+ AuthenticationUpdate::AcquirerDetailsUpdate {+ acquirer_bin,+ acquirer_merchant_id,+ acquirer_country_code,+ } => Self {+ acquirer_bin,+ acquirer_merchant_id,+ acquirer_country_code,+ ..Default::default()+ },}}}diff --git a/crates/diesel_models/src/business_profile.rs b/crates/diesel_models/src/business_profile.rsindex 6a52078fa3..3f2a6b35b5 100644--- a/crates/diesel_models/src/business_profile.rs+++ b/crates/diesel_models/src/business_profile.rs@@ -74,7 +74,7 @@ pub struct Profile {pub is_iframe_redirection_enabled: Option<bool>,pub is_pre_network_tokenization_enabled: Option<bool>,pub three_ds_decision_rule_algorithm: Option<serde_json::Value>,- pub acquirer_config_map: Option<common_types::domain::AcquirerConfigMap>,+ pub acquirer_config_map: Option<AcquirerConfigBucket>,pub merchant_category_code: Option<common_enums::MerchantCategoryCode>,pub merchant_country_code: Option<common_types::payments::MerchantCountryCode>,pub dispute_polling_interval: Option<primitive_wrappers::DisputePollingIntervalInHours>,@@ -210,7 +210,7 @@ pub struct ProfileUpdateInternal {pub is_iframe_redirection_enabled: Option<bool>,pub is_pre_network_tokenization_enabled: Option<bool>,pub three_ds_decision_rule_algorithm: Option<serde_json::Value>,- pub acquirer_config_map: Option<common_types::domain::AcquirerConfigMap>,+ pub acquirer_config_map: Option<AcquirerConfigBucket>,pub merchant_category_code: Option<common_enums::MerchantCategoryCode>,pub merchant_country_code: Option<common_types::payments::MerchantCountryCode>,pub dispute_polling_interval: Option<primitive_wrappers::DisputePollingIntervalInHours>,@@ -449,7 +449,7 @@ pub struct Profile {pub id: common_utils::id_type::ProfileId,pub is_iframe_redirection_enabled: Option<bool>,pub three_ds_decision_rule_algorithm: Option<serde_json::Value>,- pub acquirer_config_map: Option<common_types::domain::AcquirerConfigMap>,+ pub acquirer_config_map: Option<AcquirerConfigBucket>,pub merchant_category_code: Option<common_enums::MerchantCategoryCode>,pub merchant_country_code: Option<common_types::payments::MerchantCountryCode>,pub dispute_polling_interval: Option<primitive_wrappers::DisputePollingIntervalInHours>,@@ -879,6 +879,35 @@ pub struct WebhookDetails {common_utils::impl_to_sql_from_sql_json!(WebhookDetails);+#[derive(+ Clone, Debug, serde::Serialize, serde::Deserialize, diesel::AsExpression, diesel::FromSqlRow,+)]+#[diesel(sql_type = diesel::sql_types::Jsonb)]+#[serde(untagged)]+pub enum AcquirerConfigBucket {+ New(common_types::domain::AcquirerConfigBucket),+ Old(+ HashMap<+ common_utils::id_type::ProfileAcquirerId,+ Vec<common_types::domain::AcquirerConfig>,+ >,+ ),+}++common_utils::impl_to_sql_from_sql_json!(AcquirerConfigBucket);++impl From<AcquirerConfigBucket> for common_types::domain::AcquirerConfigBucket {+ fn from(item: AcquirerConfigBucket) -> Self {+ match item {+ AcquirerConfigBucket::New(new) => new,+ AcquirerConfigBucket::Old(old) => Self {+ default_acquirer_config: None,+ configs: old,+ },+ }+ }+}+#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, diesel::AsExpression)]#[diesel(sql_type = diesel::sql_types::Jsonb)]pub struct BusinessPaymentLinkConfig {diff --git a/crates/diesel_models/src/payment_intent.rs b/crates/diesel_models/src/payment_intent.rsindex 5edcdc091d..c69dfde9f8 100644--- a/crates/diesel_models/src/payment_intent.rs+++ b/crates/diesel_models/src/payment_intent.rs@@ -88,6 +88,7 @@ pub struct PaymentIntent {Option<common_types::payments::PartnerMerchantIdentifierDetails>,pub state_metadata: Option<PaymentIntentStateMetadata>,pub installment_options: Option<common_types::payments::InstallmentOptions>,+ pub profile_acquirer_id: Option<common_utils::id_type::ProfileAcquirerId>,pub merchant_reference_id: Option<common_utils::id_type::PaymentReferenceId>,pub billing_address: Option<Encryption>,pub shipping_address: Option<Encryption>,@@ -199,6 +200,7 @@ pub struct PaymentIntent {Option<common_types::payments::PartnerMerchantIdentifierDetails>,pub state_metadata: Option<PaymentIntentStateMetadata>,pub installment_options: Option<common_types::payments::InstallmentOptions>,+ pub profile_acquirer_id: Option<common_utils::id_type::ProfileAcquirerId>,}#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, diesel::AsExpression, PartialEq)]@@ -414,6 +416,7 @@ pub struct PaymentIntentNew {pub active_attempt_id_type: Option<common_enums::ActiveAttemptIDType>,pub state_metadata: Option<PaymentIntentStateMetadata>,pub installment_options: Option<common_types::payments::InstallmentOptions>,+ pub profile_acquirer_id: Option<common_utils::id_type::ProfileAcquirerId>,}#[cfg(feature = "v1")]@@ -505,6 +508,7 @@ pub struct PaymentIntentNew {Option<common_types::payments::PartnerMerchantIdentifierDetails>,pub state_metadata: Option<PaymentIntentStateMetadata>,pub installment_options: Option<common_types::payments::InstallmentOptions>,+ pub profile_acquirer_id: Option<common_utils::id_type::ProfileAcquirerId>,}#[cfg(feature = "v2")]@@ -515,6 +519,7 @@ pub enum PaymentIntentUpdate {status: storage_enums::IntentStatus,active_attempt_id: common_utils::id_type::GlobalAttemptId,updated_by: String,+ profile_acquirer_id: Option<common_utils::id_type::ProfileAcquirerId>,},/// Update the payment intent details on payment intent confirmation, after calling the connectorConfirmIntentPostUpdate {@@ -642,6 +647,7 @@ pub struct PaymentIntentUpdateFields {pub force_3ds_challenge: Option<bool>,pub is_iframe_redirection_enabled: Option<bool>,pub payment_channel: Option<Option<common_enums::PaymentChannel>>,+ pub profile_acquirer_id: Option<common_utils::id_type::ProfileAcquirerId>,}#[cfg(feature = "v1")]@@ -687,6 +693,7 @@ pub struct PaymentIntentUpdateFields {pub enable_overcapture: Option<common_types::primitive_wrappers::EnableOvercaptureBool>,pub shipping_cost: Option<MinorUnit>,pub installment_options: Option<common_types::payments::InstallmentOptions>,+ pub profile_acquirer_id: Option<common_utils::id_type::ProfileAcquirerId>,}// TODO: uncomment fields as necessary@@ -735,6 +742,7 @@ pub struct PaymentIntentUpdateInternal {pub is_iframe_redirection_enabled: Option<bool>,pub enable_partial_authorization: Option<EnablePartialAuthorizationBool>,pub state_metadata: Option<PaymentIntentStateMetadata>,+ pub profile_acquirer_id: Option<common_utils::id_type::ProfileAcquirerId>,}#[cfg(feature = "v2")]@@ -782,6 +790,7 @@ impl PaymentIntentUpdateInternal {is_iframe_redirection_enabled,enable_partial_authorization,state_metadata,+ profile_acquirer_id,} = self;PaymentIntent {@@ -828,6 +837,7 @@ impl PaymentIntentUpdateInternal {frm_metadata: frm_metadata.or(source.frm_metadata),request_external_three_ds_authentication: request_external_three_ds_authentication.or(source.request_external_three_ds_authentication),+ profile_acquirer_id: profile_acquirer_id.or(source.profile_acquirer_id),updated_by,force_3ds_challenge: force_3ds_challenge.or(source.force_3ds_challenge),is_iframe_redirection_enabled: is_iframe_redirection_enabled@@ -930,6 +940,7 @@ pub struct PaymentIntentUpdateInternal {pub shipping_cost: Option<MinorUnit>,pub state_metadata: Option<PaymentIntentStateMetadata>,pub installment_options: Option<common_types::payments::InstallmentOptions>,+ pub profile_acquirer_id: Option<common_utils::id_type::ProfileAcquirerId>,}#[cfg(feature = "v1")]@@ -985,6 +996,9 @@ impl PaymentIntentUpdate {enable_partial_authorization,enable_overcapture,shipping_cost,+ state_metadata: _,+ installment_options: _,+ profile_acquirer_id,..} = self.into();PaymentIntent {@@ -1048,6 +1062,7 @@ impl PaymentIntentUpdate {.or(source.enable_partial_authorization),enable_overcapture: enable_overcapture.or(source.enable_overcapture),shipping_cost: shipping_cost.or(source.shipping_cost),+ profile_acquirer_id: profile_acquirer_id.or(source.profile_acquirer_id),..source}}@@ -1113,6 +1128,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {enable_partial_authorization: None,enable_overcapture: None,shipping_cost: None,+ profile_acquirer_id: None,},PaymentIntentUpdate::StateMetadataUpdate {state_metadata,@@ -1168,6 +1184,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {enable_partial_authorization: None,enable_overcapture: None,shipping_cost: None,+ profile_acquirer_id: None,installment_options: None,},PaymentIntentUpdate::Update(value) => Self {@@ -1223,6 +1240,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {shipping_cost: value.shipping_cost,state_metadata: None,installment_options: value.installment_options,+ profile_acquirer_id: value.profile_acquirer_id,},PaymentIntentUpdate::PaymentCreateUpdate {return_url,@@ -1284,6 +1302,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {enable_partial_authorization: None,enable_overcapture: None,shipping_cost: None,+ profile_acquirer_id: None,},PaymentIntentUpdate::PGStatusUpdate {status,@@ -1342,6 +1361,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {enable_partial_authorization: None,enable_overcapture: None,shipping_cost: None,+ profile_acquirer_id: None,},PaymentIntentUpdate::MerchantStatusUpdate {status,@@ -1400,6 +1420,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {enable_partial_authorization: None,enable_overcapture: None,shipping_cost: None,+ profile_acquirer_id: None,},PaymentIntentUpdate::ResponseUpdate {// amount,@@ -1466,6 +1487,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {enable_partial_authorization: None,enable_overcapture: None,shipping_cost: None,+ profile_acquirer_id: None,},PaymentIntentUpdate::PaymentAttemptAndAttemptCountUpdate {active_attempt_id,@@ -1523,6 +1545,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {enable_partial_authorization: None,enable_overcapture: None,shipping_cost: None,+ profile_acquirer_id: None,},PaymentIntentUpdate::StatusAndAttemptUpdate {status,@@ -1581,6 +1604,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {enable_partial_authorization: None,enable_overcapture: None,shipping_cost: None,+ profile_acquirer_id: None,},PaymentIntentUpdate::ApproveUpdate {status,@@ -1638,6 +1662,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {enable_partial_authorization: None,enable_overcapture: None,shipping_cost: None,+ profile_acquirer_id: None,},PaymentIntentUpdate::RejectUpdate {status,@@ -1695,6 +1720,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {enable_partial_authorization: None,enable_overcapture: None,shipping_cost: None,+ profile_acquirer_id: None,},PaymentIntentUpdate::SurchargeApplicableUpdate {surcharge_applicable,@@ -1751,6 +1777,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {enable_partial_authorization: None,enable_overcapture: None,shipping_cost: None,+ profile_acquirer_id: None,},PaymentIntentUpdate::IncrementalAuthorizationAmountUpdate { amount } => Self {amount: Some(amount),@@ -1804,6 +1831,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {enable_partial_authorization: None,enable_overcapture: None,shipping_cost: None,+ profile_acquirer_id: None,},PaymentIntentUpdate::AuthorizationCountUpdate {authorization_count,@@ -1859,6 +1887,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {enable_partial_authorization: None,enable_overcapture: None,shipping_cost: None,+ profile_acquirer_id: None,},PaymentIntentUpdate::CompleteAuthorizeUpdate {shipping_address_id,@@ -1914,6 +1943,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {enable_partial_authorization: None,enable_overcapture: None,shipping_cost: None,+ profile_acquirer_id: None,},PaymentIntentUpdate::ManualUpdate { status, updated_by } => Self {status,@@ -1967,6 +1997,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {enable_partial_authorization: None,enable_overcapture: None,shipping_cost: None,+ profile_acquirer_id: None,},PaymentIntentUpdate::SessionResponseUpdate {tax_details,@@ -2025,6 +2056,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {enable_partial_authorization: None,enable_overcapture: None,shipping_cost: None,+ profile_acquirer_id: None,},PaymentIntentUpdate::RecurrenceUpdate { status, updated_by } => Self {status: Some(status),@@ -2078,6 +2110,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {enable_partial_authorization: None,enable_overcapture: None,shipping_cost: None,+ profile_acquirer_id: None,},}}diff --git a/crates/diesel_models/src/schema.rs b/crates/diesel_models/src/schema.rsindex 8567578d36..20ad12f8f6 100644--- a/crates/diesel_models/src/schema.rs+++ b/crates/diesel_models/src/schema.rs@@ -1321,6 +1321,8 @@ diesel::table! {partner_merchant_identifier_details -> Nullable<Jsonb>,state_metadata -> Nullable<Jsonb>,installment_options -> Nullable<Jsonb>,+ #[max_length = 64]+ profile_acquirer_id -> Nullable<Varchar>,}}diff --git a/crates/diesel_models/src/schema_v2.rs b/crates/diesel_models/src/schema_v2.rsindex 421edf355a..944f60a7ac 100644--- a/crates/diesel_models/src/schema_v2.rs+++ b/crates/diesel_models/src/schema_v2.rs@@ -1256,6 +1256,8 @@ diesel::table! {state_metadata -> Nullable<Jsonb>,installment_options -> Nullable<Jsonb>,#[max_length = 64]+ profile_acquirer_id -> Nullable<Varchar>,+ #[max_length = 64]merchant_reference_id -> Nullable<Varchar>,billing_address -> Nullable<Bytea>,shipping_address -> Nullable<Bytea>,diff --git a/crates/hyperswitch_domain_models/src/authentication.rs b/crates/hyperswitch_domain_models/src/authentication.rsindex 8b52610995..26d28fc0f0 100644--- a/crates/hyperswitch_domain_models/src/authentication.rs+++ b/crates/hyperswitch_domain_models/src/authentication.rs@@ -543,6 +543,13 @@ pub enum AuthenticationUpdate {trans_status: common_enums::TransactionStatus,authentication_status: common_enums::AuthenticationStatus,},+ /// Used after bucket-based acquirer resolution in authentication_eligibility_core+ /// to persist the dynamically resolved acquirer details back to the authentication record.+ AcquirerDetailsUpdate {+ acquirer_bin: Option<String>,+ acquirer_merchant_id: Option<String>,+ acquirer_country_code: Option<String>,+ },}impl From<AuthenticationUpdate> for diesel_models::authentication::AuthenticationUpdate {@@ -698,6 +705,15 @@ impl From<AuthenticationUpdate> for diesel_models::authentication::Authenticatiotrans_status,authentication_status,},+ AuthenticationUpdate::AcquirerDetailsUpdate {+ acquirer_bin,+ acquirer_merchant_id,+ acquirer_country_code,+ } => Self::AcquirerDetailsUpdate {+ acquirer_bin,+ acquirer_merchant_id,+ acquirer_country_code,+ },}}}diff --git a/crates/hyperswitch_domain_models/src/business_profile.rs b/crates/hyperswitch_domain_models/src/business_profile.rsindex 0fcbc30e79..3d7b628af3 100644--- a/crates/hyperswitch_domain_models/src/business_profile.rs+++ b/crates/hyperswitch_domain_models/src/business_profile.rs@@ -83,7 +83,7 @@ pub struct Profile {pub is_iframe_redirection_enabled: Option<bool>,pub is_pre_network_tokenization_enabled: bool,pub three_ds_decision_rule_algorithm: Option<serde_json::Value>,- pub acquirer_config_map: Option<common_types::domain::AcquirerConfigMap>,+ pub acquirer_config_map: Option<common_types::domain::AcquirerConfigBucket>,pub merchant_category_code: Option<api_enums::MerchantCategoryCode>,pub merchant_country_code: Option<common_types::payments::MerchantCountryCode>,pub dispute_polling_interval: Option<primitive_wrappers::DisputePollingIntervalInHours>,@@ -430,8 +430,8 @@ pub enum ProfileUpdate {CardTestingSecretKeyUpdate {card_testing_secret_key: OptionalEncryptableName,},- AcquirerConfigMapUpdate {- acquirer_config_map: Option<common_types::domain::AcquirerConfigMap>,+ AcquirerConfigBucketUpdate {+ acquirer_config_map: Option<common_types::domain::AcquirerConfigBucket>,},DefaultRoutingFallbackUpdate {default_fallback_routing: Option<pii::SecretSerdeValue>,@@ -955,7 +955,7 @@ impl From<ProfileUpdate> for ProfileUpdateInternal {payment_method_blocking: None,default_fallback_routing: None,},- ProfileUpdate::AcquirerConfigMapUpdate {+ ProfileUpdate::AcquirerConfigBucketUpdate {acquirer_config_map,} => Self {profile_name: None,@@ -1003,7 +1003,8 @@ impl From<ProfileUpdate> for ProfileUpdateInternal {is_iframe_redirection_enabled: None,is_pre_network_tokenization_enabled: None,three_ds_decision_rule_algorithm: None,- acquirer_config_map,+ acquirer_config_map: acquirer_config_map+ .map(diesel_models::business_profile::AcquirerConfigBucket::New),merchant_category_code: None,merchant_country_code: None,dispute_polling_interval: None,@@ -1153,7 +1154,9 @@ impl Conversion for Profile {is_iframe_redirection_enabled: self.is_iframe_redirection_enabled,is_pre_network_tokenization_enabled: Some(self.is_pre_network_tokenization_enabled),three_ds_decision_rule_algorithm: self.three_ds_decision_rule_algorithm,- acquirer_config_map: self.acquirer_config_map,+ acquirer_config_map: self+ .acquirer_config_map+ .map(diesel_models::business_profile::AcquirerConfigBucket::New),merchant_category_code: self.merchant_category_code,merchant_country_code: self.merchant_country_code,dispute_polling_interval: self.dispute_polling_interval,@@ -1305,7 +1308,9 @@ impl Conversion for Profile {.is_pre_network_tokenization_enabled.unwrap_or(false),three_ds_decision_rule_algorithm: item.three_ds_decision_rule_algorithm,- acquirer_config_map: item.acquirer_config_map,+ acquirer_config_map: item+ .acquirer_config_map+ .map(common_types::domain::AcquirerConfigBucket::from),merchant_category_code: item.merchant_category_code,merchant_country_code: item.merchant_country_code,dispute_polling_interval: item.dispute_polling_interval,@@ -1627,16 +1632,51 @@ impl Profile {&self,network: common_enums::CardNetwork,) -> Option<AcquirerConfig> {- // iterate over acquirer_config_map and find the acquirer config for the given network+ // Flatten all buckets and search across them for an AcquirerConfig matching the network.self.acquirer_config_map.as_ref().and_then(|acquirer_config_map| {acquirer_config_map- .0- .iter()- .find(|&(_, acquirer_config)| acquirer_config.network == network)+ .configs+ .values()+ .flat_map(|bucket| bucket.iter())+ .find(|cfg| cfg.network == network)+ .cloned()})- .map(|(_, acquirer_config)| acquirer_config.clone())+ }++ /// Resolve an `AcquirerConfig` for a specific `profile_acquirer_id` bucket and `network`.+ /// Use this when the authentication record already has a `profile_acquirer_id` scoped to a+ /// particular acquirer, so the lookup is restricted to that bucket only.+ #[cfg(feature = "v1")]+ pub fn get_acquirer_details_for_profile_acquirer(+ &self,+ profile_acquirer_id: &common_utils::id_type::ProfileAcquirerId,+ network: common_enums::CardNetwork,+ ) -> Option<AcquirerConfig> {+ self.acquirer_config_map+ .as_ref()+ .and_then(|map| map.configs.get(profile_acquirer_id))+ .and_then(|bucket| bucket.iter().find(|cfg| cfg.network == network).cloned())+ }++ /// Resolve an `AcquirerConfig` from the default bucket or fallback to the first bucket.+ #[cfg(feature = "v1")]+ pub fn get_default_acquirer_details_from_network(+ &self,+ network: common_enums::CardNetwork,+ ) -> Option<AcquirerConfig> {+ self.acquirer_config_map.as_ref().and_then(|map| {+ // Get the default bucket from the default_acquirer_config identifier, or fallback to the first bucket+ let default_bucket = map+ .default_acquirer_config+ .as_ref()+ .and_then(|id| map.configs.get(id))+ .or_else(|| map.configs.values().next());++ default_bucket+ .and_then(|bucket| bucket.iter().find(|cfg| cfg.network == network).cloned())+ })}#[cfg(feature = "v1")]diff --git a/crates/hyperswitch_domain_models/src/payments.rs b/crates/hyperswitch_domain_models/src/payments.rsindex 1e6ebbaac8..a1ef5b1a94 100644--- a/crates/hyperswitch_domain_models/src/payments.rs+++ b/crates/hyperswitch_domain_models/src/payments.rs@@ -150,6 +150,7 @@ pub struct PaymentIntent {Option<common_types::payments::PartnerMerchantIdentifierDetails>,pub state_metadata: Option<common_types::payments::PaymentIntentStateMetadata>,pub installment_options: Option<Vec<common_types::payments::InstallmentOption>>,+ pub profile_acquirer_id: Option<id_type::ProfileAcquirerId>,}impl PaymentIntent {@@ -804,6 +805,7 @@ pub struct PaymentIntent {pub attempt_count: i16,/// The profile id for the payment.pub profile_id: id_type::ProfileId,+ pub profile_acquirer_id: Option<id_type::ProfileAcquirerId>,/// The payment link id for the payment. This is generated only if `enable_payment_link` is set to true.pub payment_link_id: Option<String>,/// This Denotes the action(approve or reject) taken by merchant in case of manual review.@@ -1078,6 +1080,7 @@ impl PaymentIntent {enable_partial_authorization: request.enable_partial_authorization.unwrap_or(false.into()),+ profile_acquirer_id: None,})}diff --git a/crates/hyperswitch_domain_models/src/payments/payment_intent.rs b/crates/hyperswitch_domain_models/src/payments/payment_intent.rsindex 816d79caa4..c71e4e0546 100644--- a/crates/hyperswitch_domain_models/src/payments/payment_intent.rs+++ b/crates/hyperswitch_domain_models/src/payments/payment_intent.rs@@ -221,6 +221,7 @@ pub struct PaymentIntentUpdateFields {pub enable_partial_authorization: Option<primitive_wrappers::EnablePartialAuthorizationBool>,pub active_attempt_id_type: Option<common_enums::ActiveAttemptIDType>,pub active_attempts_group_id: Option<id_type::GlobalAttemptGroupId>,+ pub profile_acquirer_id: Option<id_type::ProfileAcquirerId>,}#[cfg(feature = "v1")]@@ -267,6 +268,7 @@ pub struct PaymentIntentUpdateFields {pub enable_overcapture: Option<primitive_wrappers::EnableOvercaptureBool>,pub shipping_cost: Option<MinorUnit>,pub installment_options: Option<Vec<common_types::payments::InstallmentOption>>,+ pub profile_acquirer_id: Option<id_type::ProfileAcquirerId>,}#[cfg(feature = "v1")]@@ -491,6 +493,7 @@ pub struct PaymentIntentUpdateInternal {pub shipping_cost: Option<MinorUnit>,pub state_metadata: Option<common_types::payments::PaymentIntentStateMetadata>,pub installment_options: Option<Vec<common_types::payments::InstallmentOption>>,+ pub profile_acquirer_id: Option<id_type::ProfileAcquirerId>,}// This conversion is used in the `update_payment_intent` function@@ -545,6 +548,7 @@ impl TryFrom<PaymentIntentUpdate> for diesel_models::PaymentIntentUpdateInternalis_iframe_redirection_enabled: None,enable_partial_authorization: None,state_metadata: None,+ profile_acquirer_id: None,}),PaymentIntentUpdate::ConfirmIntentPostUpdate {@@ -594,6 +598,7 @@ impl TryFrom<PaymentIntentUpdate> for diesel_models::PaymentIntentUpdateInternalis_iframe_redirection_enabled: None,enable_partial_authorization: None,state_metadata: None,+ profile_acquirer_id: None,}),PaymentIntentUpdate::SyncUpdate {status,@@ -641,6 +646,7 @@ impl TryFrom<PaymentIntentUpdate> for diesel_models::PaymentIntentUpdateInternalis_iframe_redirection_enabled: None,enable_partial_authorization: None,state_metadata: None,+ profile_acquirer_id: None,}),PaymentIntentUpdate::CaptureUpdate {status,@@ -688,6 +694,7 @@ impl TryFrom<PaymentIntentUpdate> for diesel_models::PaymentIntentUpdateInternalis_iframe_redirection_enabled: None,enable_partial_authorization: None,state_metadata: None,+ profile_acquirer_id: None,}),PaymentIntentUpdate::SessionIntentUpdate {prerouting_algorithm,@@ -738,6 +745,7 @@ impl TryFrom<PaymentIntentUpdate> for diesel_models::PaymentIntentUpdateInternalis_iframe_redirection_enabled: None,enable_partial_authorization: None,state_metadata: None,+ profile_acquirer_id: None,}),PaymentIntentUpdate::UpdateIntent(boxed_intent) => {let PaymentIntentUpdateFields {@@ -778,6 +786,7 @@ impl TryFrom<PaymentIntentUpdate> for diesel_models::PaymentIntentUpdateInternalenable_partial_authorization,active_attempt_id_type,active_attempts_group_id,+ profile_acquirer_id,} = *boxed_intent;Ok(Self {status: None,@@ -827,6 +836,7 @@ impl TryFrom<PaymentIntentUpdate> for diesel_models::PaymentIntentUpdateInternalis_iframe_redirection_enabled,enable_partial_authorization,state_metadata: None,+ profile_acquirer_id,})}PaymentIntentUpdate::RecordUpdate {@@ -877,6 +887,7 @@ impl TryFrom<PaymentIntentUpdate> for diesel_models::PaymentIntentUpdateInternalis_iframe_redirection_enabled: None,enable_partial_authorization: None,state_metadata: None,+ profile_acquirer_id: None,}),PaymentIntentUpdate::VoidUpdate { status, updated_by } => Ok(Self {status: Some(status),@@ -921,6 +932,7 @@ impl TryFrom<PaymentIntentUpdate> for diesel_models::PaymentIntentUpdateInternalis_iframe_redirection_enabled: None,enable_partial_authorization: None,state_metadata: None,+ profile_acquirer_id: None,}),PaymentIntentUpdate::AttemptGroupUpdate {updated_by,@@ -968,6 +980,7 @@ impl TryFrom<PaymentIntentUpdate> for diesel_models::PaymentIntentUpdateInternalis_iframe_redirection_enabled: None,enable_partial_authorization: None,state_metadata: None,+ profile_acquirer_id: None,}),PaymentIntentUpdate::SplitPaymentStatusUpdate { status, updated_by } => Ok(Self {status: Some(status),@@ -1011,6 +1024,7 @@ impl TryFrom<PaymentIntentUpdate> for diesel_models::PaymentIntentUpdateInternalis_iframe_redirection_enabled: None,enable_partial_authorization: None,state_metadata: None,+ profile_acquirer_id: None,}),}}@@ -1274,6 +1288,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {enable_overcapture: None,shipping_cost: None,installment_options: None,+ profile_acquirer_id: None,},PaymentIntentUpdate::RecurrenceUpdate { status, updated_by } => Self {status: Some(status),@@ -1326,6 +1341,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {enable_overcapture: None,shipping_cost: None,installment_options: None,+ profile_acquirer_id: None,},}}@@ -1432,6 +1448,7 @@ impl From<PaymentIntentUpdate> for DieselPaymentIntentUpdate {installment_options: value.installment_options.map(common_types::payments::InstallmentOptions),+ profile_acquirer_id: value.profile_acquirer_id,}))}PaymentIntentUpdate::PaymentCreateUpdate {@@ -1607,6 +1624,7 @@ impl From<PaymentIntentUpdateInternal> for diesel_models::PaymentIntentUpdateIntshipping_cost,state_metadata,installment_options,+ profile_acquirer_id,} = value;Self {amount,@@ -1661,6 +1679,7 @@ impl From<PaymentIntentUpdateInternal> for diesel_models::PaymentIntentUpdateIntstate_metadata,installment_options: installment_options.map(common_types::payments::InstallmentOptions),+ profile_acquirer_id,}}}@@ -2045,6 +2064,7 @@ impl behaviour::Conversion for PaymentIntent {is_iframe_redirection_enabled,is_payment_id_from_merchant,enable_partial_authorization,+ profile_acquirer_id,} = self;Ok(DieselPaymentIntent {skip_external_tax_calculation: Some(amount_details.get_external_tax_action_as_bool()),@@ -2156,6 +2176,7 @@ impl behaviour::Conversion for PaymentIntent {partner_merchant_identifier_details: None,state_metadata: None,installment_options: None,+ profile_acquirer_id,})}async fn convert_back(@@ -2309,6 +2330,7 @@ impl behaviour::Conversion for PaymentIntent {enable_partial_authorization: storage_model.enable_partial_authorization.unwrap_or(false.into()),+ profile_acquirer_id: storage_model.profile_acquirer_id,})}.await@@ -2420,6 +2442,7 @@ impl behaviour::Conversion for PaymentIntent {active_attempts_group_id: self.active_attempts_group_id,state_metadata: None,installment_options: None,+ profile_acquirer_id: self.profile_acquirer_id,})}}@@ -2511,6 +2534,7 @@ impl behaviour::Conversion for PaymentIntent {installment_options: self.installment_options.map(common_types::payments::InstallmentOptions),+ profile_acquirer_id: self.profile_acquirer_id,})}@@ -2627,6 +2651,7 @@ impl behaviour::Conversion for PaymentIntent {.partner_merchant_identifier_details,state_metadata: storage_model.state_metadata,installment_options: storage_model.installment_options.map(|o| o.0),+ profile_acquirer_id: storage_model.profile_acquirer_id,})}.await@@ -2716,6 +2741,7 @@ impl behaviour::Conversion for PaymentIntent {installment_options: self.installment_options.map(common_types::payments::InstallmentOptions),+ profile_acquirer_id: self.profile_acquirer_id,})}}diff --git a/crates/openapi/src/openapi.rs b/crates/openapi/src/openapi.rsindex dd194eef6a..5d9e0ecb2b 100644--- a/crates/openapi/src/openapi.rs+++ b/crates/openapi/src/openapi.rs@@ -383,7 +383,7 @@ Never share your secret api keys. Keep them guarded and secure.api_models::payment_methods::CustomerPaymentMethodUpdateResponse,api_models::payment_methods::CustomerPaymentMethod,common_types::three_ds_decision_rule_engine::ThreeDSDecisionRule,- common_types::domain::AcquirerConfigMap,+ common_types::domain::AcquirerConfigBucket,common_types::domain::AcquirerConfig,api_models::payment_methods::PaymentMethodListResponse,api_models::payment_methods::PaymentMethodListIntentData,@@ -1015,6 +1015,8 @@ Never share your secret api keys. Keep them guarded and secure.api_models::profile_acquirer::ProfileAcquirerCreate,api_models::profile_acquirer::ProfileAcquirerUpdate,api_models::profile_acquirer::ProfileAcquirerResponse,+ api_models::profile_acquirer::ProfileAcquirerConfigsResponse,+ api_models::profile_acquirer::AcquirerBucketConfigResponse,euclid::frontend::dir::enums::CustomerDevicePlatform,euclid::frontend::dir::enums::CustomerDeviceType,euclid::frontend::dir::enums::CustomerDeviceDisplaySize,@@ -1067,6 +1069,7 @@ Never share your secret api keys. Keep them guarded and secure.common_utils::id_type::PaymentId,common_utils::id_type::ProfileId,common_utils::id_type::AuthenticationId,+ common_utils::id_type::ProfileAcquirerId,api_models::open_router::RankingAlgorithm,api_models::open_router::TxnStatus,api_models::open_router::PriorityLogicOutput,diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rsindex 6167210a4f..b0e88e61f8 100644--- a/crates/router/src/core/payments/helpers.rs+++ b/crates/router/src/core/payments/helpers.rs@@ -4669,6 +4669,7 @@ mod tests {partner_merchant_identifier_details: None,state_metadata: None,installment_options: None,+ profile_acquirer_id: None,};let req_cs = Some("1".to_string());assert!(authenticate_client_secret(req_cs.as_ref(), &payment_intent).is_ok());@@ -4760,6 +4761,7 @@ mod tests {partner_merchant_identifier_details: None,state_metadata: None,installment_options: None,+ profile_acquirer_id: None,};let req_cs = Some("1".to_string());assert!(authenticate_client_secret(req_cs.as_ref(), &payment_intent,).is_err())@@ -4849,6 +4851,7 @@ mod tests {partner_merchant_identifier_details: None,state_metadata: None,installment_options: None,+ profile_acquirer_id: None,};let req_cs = Some("1".to_string());assert!(authenticate_client_secret(req_cs.as_ref(), &payment_intent).is_err())@@ -8451,9 +8454,11 @@ pub async fn get_payment_external_authentication_flow_during_confirm<F: Clone>(connector_data.merchant_connector_id.as_ref(),).await?;- let acquirer_details = payment_connector_mca++ let profile_acquirer_id = payment_data.payment_intent.profile_acquirer_id.as_ref();+ let acquirer_details = match payment_connector_mca.get_metadata()- .clone()+ .as_ref().and_then(|metadata| {metadata.peek()@@ -8471,7 +8476,38 @@ pub async fn get_payment_external_authentication_flow_during_confirm<F: Clone>();}).ok()- });+ }) {+ Some(details) => Some(details),+ None => {+ let network = card+ .card_network+ .as_ref()+ .cloned()+ .ok_or(errors::ApiErrorResponse::PreconditionFailed {+ message: "Card network not found".to_string(),+ })?;++ let resolved = match profile_acquirer_id {+ Some(id) => business_profile+ .get_acquirer_details_for_profile_acquirer(id, network.clone())+ .ok_or(errors::ApiErrorResponse::PreconditionFailed {+ message: format!("Acquirer configuration not found for network {:?} in bucket {:?}", network, id),+ })?,+ None => business_profile+ .get_default_acquirer_details_from_network(network.clone())+ .ok_or(errors::ApiErrorResponse::PreconditionFailed {+ message: format!("Acquirer configuration not found for network {:?} in default bucket", network),+ })?,+ };++ Some(authentication::types::AcquirerDetails {+ acquirer_bin: resolved.acquirer_bin.unwrap_or_default(),+ acquirer_merchant_id: resolved.acquirer_assigned_merchant_id.unwrap_or_default(),+ acquirer_country_code: resolved.acquirer_country_code,+ })+ }+ };+Some(PaymentExternalAuthenticationFlow::PreAuthenticationFlow {card: Box::new(card),token,diff --git a/crates/router/src/core/payments/operations/external_vault_proxy_payment_intent.rs b/crates/router/src/core/payments/operations/external_vault_proxy_payment_intent.rsindex abc6189472..161f345901 100644--- a/crates/router/src/core/payments/operations/external_vault_proxy_payment_intent.rs+++ b/crates/router/src/core/payments/operations/external_vault_proxy_payment_intent.rs@@ -520,7 +520,7 @@ impl<F: Clone + Sync> UpdateTracker<F, PaymentConfirmData<F>, ExternalVaultProxyhyperswitch_domain_models::payments::payment_intent::PaymentIntentUpdate::ConfirmIntent {status: intent_status,updated_by: storage_scheme.to_string(),- active_attempt_id: Some(payment_data.payment_attempt.id.clone()),+ active_attempt_id: Some(payment_data.payment_attempt.id.clone())};let authentication_type = payment_datadiff --git a/crates/router/src/core/payments/operations/payment_confirm.rs b/crates/router/src/core/payments/operations/payment_confirm.rsindex cadaa355e9..48e1946110 100644--- a/crates/router/src/core/payments/operations/payment_confirm.rs+++ b/crates/router/src/core/payments/operations/payment_confirm.rs@@ -1695,7 +1695,7 @@ impl<F: Clone + Send + Sync> Domain<F, api::PaymentsRequest, PaymentData<F>> foracquirer: acquirer_config.as_ref().map(|acquirer| {api_models::three_ds_decision_rule::AcquirerData {country: acquirer_country,- fraud_rate: Some(acquirer.acquirer_fraud_rate),+ fraud_rate: acquirer.acquirer_fraud_rate,}}),},@@ -1961,13 +1961,25 @@ impl<F: Clone + Send + Sync> Domain<F, api::PaymentsRequest, PaymentData<F>> forplatform.get_initiator(),).await?;+ // Resolve acquirer details from the bucket using the card network from payment_method_data.+ // The bucket is keyed by profile_acquirer_id; within it we match the card's network.+ let resolved_card_network = payment_data+ .payment_method_data+ .as_ref()+ .and_then(|pmd| match pmd {+ domain::PaymentMethodData::Card(card) => card.card_network.clone(),+ domain::PaymentMethodData::CardWithOptionalCVC(card) => card.card_network.clone(),+ _ => None,+ });let acquirer_configs = authentication.profile_acquirer_id.clone()- .and_then(|acquirer_id| {+ .zip(resolved_card_network)+ .and_then(|(acquirer_id, network)| {business_profile.acquirer_config_map.as_ref()- .and_then(|acquirer_config_map| acquirer_config_map.0.get(&acquirer_id).cloned())+ .and_then(|acquirer_config_map| acquirer_config_map.configs.get(&acquirer_id))+ .and_then(|bucket| bucket.iter().find(|cfg| cfg.network == network).cloned())});let metadata: Option<ThreeDsMetaData> = three_ds_connector_account.get_metadata()@@ -2010,7 +2022,7 @@ impl<F: Clone + Send + Sync> Domain<F, api::PaymentsRequest, PaymentData<F>> forlet merchant_details = Some(unified_authentication_service::MerchantDetails {merchant_id: Some(authentication.merchant_id.get_string_repr().to_string()),- merchant_name: acquirer_configs.clone().map(|detail| detail.merchant_name.clone()).or(metadata.clone().and_then(|metadata| metadata.merchant_name)),+ merchant_name: acquirer_configs.clone().and_then(|detail| detail.merchant_name.clone()).or(metadata.clone().and_then(|metadata| metadata.merchant_name)),merchant_category_code: merchant_category_code.clone(),endpoint_prefix: metadata.clone().and_then(|metadata| metadata.endpoint_prefix),three_ds_requestor_url: business_profile.authentication_connector_details.clone().map(|details| details.three_ds_requestor_url),@@ -2847,6 +2859,10 @@ impl<F: Clone + Sync> UpdateTracker<F, PaymentData<F>, api::PaymentsRequest> for.payment_intent.installment_options.clone(),+ profile_acquirer_id: payment_data+ .payment_intent+ .profile_acquirer_id+ .clone(),})),&m_key_store,storage_scheme,diff --git a/crates/router/src/core/payments/operations/payment_create.rs b/crates/router/src/core/payments/operations/payment_create.rsindex 9d58f3cd32..32e4682252 100644--- a/crates/router/src/core/payments/operations/payment_create.rs+++ b/crates/router/src/core/payments/operations/payment_create.rs@@ -1967,6 +1967,7 @@ impl PaymentCreate {.clone(),state_metadata: None,installment_options: request.installment_options.clone(),+ profile_acquirer_id: request.profile_acquirer_id.clone(),})}}diff --git a/crates/router/src/core/payments/operations/payment_update.rs b/crates/router/src/core/payments/operations/payment_update.rsindex 1b9eb6c71f..6c6565f592 100644--- a/crates/router/src/core/payments/operations/payment_update.rs+++ b/crates/router/src/core/payments/operations/payment_update.rs@@ -1098,7 +1098,8 @@ impl<F: Clone + Sync> UpdateTracker<F, PaymentData<F>, api::PaymentsRequest> for.enable_partial_authorization,enable_overcapture: payment_data.payment_intent.enable_overcapture,shipping_cost,- installment_options: payment_data.payment_intent.installment_options,+ installment_options: payment_data.payment_intent.installment_options.clone(),+ profile_acquirer_id: payment_data.payment_intent.profile_acquirer_id.clone(),})),key_store,storage_scheme,diff --git a/crates/router/src/core/payments/operations/payment_update_intent.rs b/crates/router/src/core/payments/operations/payment_update_intent.rsindex 541f90c8b8..c3a5e34824 100644--- a/crates/router/src/core/payments/operations/payment_update_intent.rs+++ b/crates/router/src/core/payments/operations/payment_update_intent.rs@@ -397,6 +397,7 @@ impl<F: Clone> UpdateTracker<F, payments::PaymentIntentData<F>, PaymentsUpdateInenable_partial_authorization: Some(intent.enable_partial_authorization),active_attempts_group_id: intent.active_attempts_group_id,active_attempt_id_type: Some(intent.active_attempt_id_type),+ profile_acquirer_id: intent.profile_acquirer_id,}));let new_payment_intent = dbdiff --git a/crates/router/src/core/profile_acquirer.rs b/crates/router/src/core/profile_acquirer.rsindex 9f47a61bc0..2372f7e647 100644--- a/crates/router/src/core/profile_acquirer.rs+++ b/crates/router/src/core/profile_acquirer.rs@@ -25,50 +25,46 @@ pub async fn create_profile_acquirer(id: request.profile_id.get_string_repr().to_owned(),})?;+ let has_existing_default = business_profile+ .acquirer_config_map+ .as_ref()+ .map(|map| map.default_acquirer_config.is_some())+ .unwrap_or(false);++ let is_default = if !has_existing_default {+ true+ } else {+ request.is_default.unwrap_or(false)+ };+let incoming_acquirer_config = common_types::domain::AcquirerConfig {- acquirer_assigned_merchant_id: request.acquirer_assigned_merchant_id.clone(),- merchant_name: request.merchant_name.clone(),+ acquirer_assigned_merchant_id: Some(request.acquirer_assigned_merchant_id.clone()),+ merchant_name: Some(request.merchant_name.clone()),network: request.network.clone(),- acquirer_bin: request.acquirer_bin.clone(),+ acquirer_bin: Some(request.acquirer_bin.clone()),acquirer_ica: request.acquirer_ica.clone(),acquirer_fraud_rate: request.acquirer_fraud_rate,+ acquirer_country_code: request.acquirer_country_code.clone(),};- // Check for duplicates before proceeding+ // Initialize the new bucket as a Vec containing its first AcquirerConfig entry.+ let configs_map = business_profile.acquirer_config_map.get_or_insert_with(|| {+ common_types::domain::AcquirerConfigBucket {+ default_acquirer_config: None,+ configs: std::collections::HashMap::new(),+ }+ });- business_profile- .acquirer_config_map- .as_ref()- .map_or(Ok(()), |configs_wrapper| {- match configs_wrapper.0.values().any(|existing_config| existing_config == &incoming_acquirer_config) {- true => Err(error_stack::report!(- errors::ApiErrorResponse::GenericDuplicateError {- message: format!(- "Duplicate acquirer configuration found for profile_id: {}. Conflicting configuration: {:?}",- request.profile_id.get_string_repr(),- incoming_acquirer_config- ),- }- )),- false => Ok(()),- }- })?;-- // Get a mutable reference to the HashMap inside AcquirerConfigMap,- // initializing if it's None or the inner HashMap is not present.- let configs_map = &mut business_profile- .acquirer_config_map- .get_or_insert_with(|| {- common_types::domain::AcquirerConfigMap(std::collections::HashMap::new())- })- .0;-- configs_map.insert(+ configs_map.configs.insert(profile_acquirer_id.clone(),- incoming_acquirer_config.clone(),+ vec![incoming_acquirer_config.clone()],);- let profile_update = domain::ProfileUpdate::AcquirerConfigMapUpdate {+ if is_default {+ configs_map.default_acquirer_config = Some(profile_acquirer_id.clone());+ }++ let profile_update = domain::ProfileUpdate::AcquirerConfigBucketUpdate {acquirer_config_map: business_profile.acquirer_config_map.clone(),};let updated_business_profile = db@@ -77,17 +73,24 @@ pub async fn create_profile_acquirer(.change_context(errors::ApiErrorResponse::InternalServerError).attach_printable("Failed to update business profile with new acquirer config")?;- let updated_acquire_details = updated_business_profile+ // Retrieve the specific entry we just inserted from the updated profile.+ let updated_acquirer_config = updated_business_profile.acquirer_config_map.as_ref()- .and_then(|acquirer_configs_wrapper| acquirer_configs_wrapper.0.get(&profile_acquirer_id))+ .and_then(|wrapper| wrapper.configs.get(&profile_acquirer_id))+ .and_then(|bucket| {+ bucket+ .iter()+ .find(|cfg| cfg.network == incoming_acquirer_config.network)+ }).ok_or(errors::ApiErrorResponse::InternalServerError).attach_printable("Failed to get updated acquirer config")?;let response = profile_acquirer::ProfileAcquirerResponse::from((profile_acquirer_id,&request.profile_id,- updated_acquire_details,+ Some(updated_acquirer_config),+ is_default,));Ok(api::ApplicationResponse::Json(response))@@ -120,61 +123,60 @@ pub async fn update_profile_acquirer_config(}).attach_printable("no acquirer config found in business profile")?;- let mut potential_updated_config = acquirer_config_map- .0- .get(&profile_acquirer_id)- .ok_or_else(|| errors::ApiErrorResponse::ProfileAcquirerNotFound {- profile_id: profile_id.get_string_repr().to_owned(),- profile_acquirer_id: profile_acquirer_id.get_string_repr().to_owned(),- })?- .clone();+ let default_bucket_id = acquirer_config_map.default_acquirer_config.clone();- // updating value in existing acquirer config- request- .acquirer_assigned_merchant_id- .map(|val| potential_updated_config.acquirer_assigned_merchant_id = val);- request- .merchant_name- .map(|val| potential_updated_config.merchant_name = val);- request- .network- .map(|val| potential_updated_config.network = val);- request- .acquirer_bin- .map(|val| potential_updated_config.acquirer_bin = val);- request- .acquirer_ica- .map(|val| potential_updated_config.acquirer_ica = Some(val.clone()));- request- .acquirer_fraud_rate- .map(|val| potential_updated_config.acquirer_fraud_rate = val);-- // checking for duplicates in the acquirerConfigMap- match acquirer_config_map- .0- .iter()- .find(|(_existing_id, existing_config_val_ref)| {- **existing_config_val_ref == potential_updated_config- }) {- Some((conflicting_id_of_found_item, _)) => {- Err(error_stack::report!(errors::ApiErrorResponse::GenericDuplicateError {- message: format!(- "Duplicate acquirer configuration. This configuration already exists for profile_acquirer_id '{}' under profile_id '{}'.",- conflicting_id_of_found_item.get_string_repr(),- profile_id.get_string_repr()- ),- }))+ // Verify the target bucket (profile_acquirer_id) exists.+ if !acquirer_config_map+ .configs+ .contains_key(&profile_acquirer_id)+ {+ return Err(error_stack::report!(+ errors::ApiErrorResponse::ProfileAcquirerNotFound {+ profile_id: profile_id.get_string_repr().to_owned(),+ profile_acquirer_id: profile_acquirer_id.get_string_repr().to_owned(),+ }+ ));}- None => Ok(()),- }?;- acquirer_config_map- .0- .insert(profile_acquirer_id.clone(), potential_updated_config);+ // `network` is mandatory on update — find whether a slot for this network already exists in the bucket.+ let is_default = request+ .is_default+ .unwrap_or_else(|| default_bucket_id.as_ref() == Some(&profile_acquirer_id));++ let default_bucket_changed = apply_default_bucket_change(+ acquirer_config_map,+ &profile_acquirer_id,+ &default_bucket_id,+ request.is_default,+ );++ request+ .network+ .clone()+ .map(|target_network| {+ upsert_acquirer_config_in_bucket(+ acquirer_config_map,+ &profile_acquirer_id,+ target_network,+ &request,+ default_bucket_changed,+ )+ })+ .unwrap_or_else(|| {+ if default_bucket_changed {+ Ok(())+ } else {+ Err(error_stack::report!(+ errors::ApiErrorResponse::InvalidRequestData {+ message: "A `network` must be provided to update an acquirer configuration, unless you are only changing the `is_default` fallback status of this entire bucket.".to_string(),+ }+ ))+ }+ })?;let updated_map_for_db_update = business_profile.acquirer_config_map.clone();- let profile_update = domain::ProfileUpdate::AcquirerConfigMapUpdate {+ let profile_update = domain::ProfileUpdate::AcquirerConfigBucketUpdate {acquirer_config_map: updated_map_for_db_update,};@@ -184,18 +186,118 @@ pub async fn update_profile_acquirer_config(.change_context(errors::ApiErrorResponse::InternalServerError).attach_printable("Failed to update business profile with updated acquirer config")?;- let final_acquirer_details = updated_business_profile+ let final_acquirer_config = updated_business_profile.acquirer_config_map.as_ref()- .and_then(|configs_wrapper| configs_wrapper.0.get(&profile_acquirer_id))- .ok_or(errors::ApiErrorResponse::InternalServerError)- .attach_printable("Failed to get updated acquirer config after DB update")?;+ .and_then(|wrapper| wrapper.configs.get(&profile_acquirer_id))+ .and_then(|bucket| {+ if let Some(nw) = request.network.as_ref() {+ bucket.iter().find(|cfg| cfg.network == *nw)+ } else {+ None // is_default-only update: no specific network was modified+ }+ });let response = profile_acquirer::ProfileAcquirerResponse::from((profile_acquirer_id,&profile_id,- final_acquirer_details,+ final_acquirer_config,+ is_default,));Ok(api::ApplicationResponse::Json(response))}++/// Updates the `default_acquirer_config` pointer on the map and returns whether a change was made.+#[cfg(all(feature = "olap", feature = "v1"))]+fn apply_default_bucket_change(+ config_map: &mut common_types::domain::AcquirerConfigBucket,+ profile_acquirer_id: &common_utils::id_type::ProfileAcquirerId,+ current_default_id: &Option<common_utils::id_type::ProfileAcquirerId>,+ is_default_request: Option<bool>,+) -> bool {+ match is_default_request {+ Some(true) if current_default_id.as_ref() != Some(profile_acquirer_id) => {+ config_map.default_acquirer_config = Some(profile_acquirer_id.clone());+ true+ }+ Some(false) if current_default_id.as_ref() == Some(profile_acquirer_id) => {+ config_map.default_acquirer_config = None;+ true+ }+ _ => false,+ }+}++/// Builds an upserted `AcquirerConfig` from the request, checks for exact duplicates,+/// and writes it into the correct slot of the given bucket.+#[cfg(all(feature = "olap", feature = "v1"))]+fn upsert_acquirer_config_in_bucket(+ config_map: &mut common_types::domain::AcquirerConfigBucket,+ profile_acquirer_id: &common_utils::id_type::ProfileAcquirerId,+ target_network: common_enums::enums::CardNetwork,+ request: &profile_acquirer::ProfileAcquirerUpdate,+ default_bucket_changed: bool,+) -> error_stack::Result<(), errors::ApiErrorResponse> {+ let bucket = config_map+ .configs+ .get_mut(profile_acquirer_id)+ .ok_or(errors::ApiErrorResponse::InternalServerError)+ .attach_printable("bucket was verified above but vanished")?;++ let existing_pos = bucket.iter().position(|cfg| cfg.network == target_network);++ let base = existing_pos+ .and_then(|pos| bucket.get(pos).cloned())+ .unwrap_or(common_types::domain::AcquirerConfig {+ network: target_network,+ acquirer_assigned_merchant_id: None,+ merchant_name: None,+ acquirer_bin: None,+ acquirer_ica: None,+ acquirer_fraud_rate: None,+ acquirer_country_code: None,+ });++ let upserted_config = common_types::domain::AcquirerConfig {+ acquirer_assigned_merchant_id: request+ .acquirer_assigned_merchant_id+ .clone()+ .or(base.acquirer_assigned_merchant_id),+ merchant_name: request.merchant_name.clone().or(base.merchant_name),+ acquirer_bin: request.acquirer_bin.clone().or(base.acquirer_bin),+ acquirer_ica: request.acquirer_ica.clone().or(base.acquirer_ica),+ acquirer_fraud_rate: request.acquirer_fraud_rate.or(base.acquirer_fraud_rate),+ acquirer_country_code: request+ .acquirer_country_code+ .clone()+ .or(base.acquirer_country_code),+ network: base.network,+ };++ // Duplicate check: reject if content is identical and no default change occurred.+ if existing_pos.and_then(|pos| bucket.get(pos)) == Some(&upserted_config)+ && !default_bucket_changed+ {+ return Err(error_stack::report!(+ errors::ApiErrorResponse::GenericDuplicateError {+ message: format!(+ "An identical configuration for network '{}' already exists in bucket '{}'.",+ upserted_config.network,+ profile_acquirer_id.get_string_repr()+ ),+ }+ ));+ }++ match existing_pos {+ Some(pos) => {+ if let Some(slot) = bucket.get_mut(pos) {+ *slot = upserted_config;+ }+ }+ None => bucket.push(upserted_config),+ }++ Ok(())+}diff --git a/crates/router/src/core/routing/helpers.rs b/crates/router/src/core/routing/helpers.rsindex cabd061e0c..59000b1921 100644--- a/crates/router/src/core/routing/helpers.rs+++ b/crates/router/src/core/routing/helpers.rs@@ -1982,7 +1982,7 @@ pub async fn enable_dynamic_routing_algorithm(dynamic_routing.disable_algorithm_id(routing_types::DynamicRoutingType::ContractBasedRouting);- enable_specific_routing_algorithm(+ Box::pin(enable_specific_routing_algorithm(state,key_store,business_profile,@@ -1991,11 +1991,11 @@ pub async fn enable_dynamic_routing_algorithm(dynamic_routing_type,dynamic_routing.success_based_algorithm,payload,- )+ )).await}routing_types::DynamicRoutingType::EliminationRouting => {- enable_specific_routing_algorithm(+ Box::pin(enable_specific_routing_algorithm(state,key_store,business_profile,@@ -2004,7 +2004,7 @@ pub async fn enable_dynamic_routing_algorithm(dynamic_routing_type,dynamic_routing.elimination_routing_algorithm,payload,- )+ )).await}routing_types::DynamicRoutingType::ContractBasedRouting => {diff --git a/crates/router/src/core/unified_authentication_service.rs b/crates/router/src/core/unified_authentication_service.rsindex 7d4bf4fea4..c62227fa99 100644--- a/crates/router/src/core/unified_authentication_service.rs+++ b/crates/router/src/core/unified_authentication_service.rs@@ -741,37 +741,20 @@ pub async fn authentication_create_core(.unwrap_or(business_profile.force_3ds_challenge),);- // Priority logic: First check req.acquirer_details, then fallback to profile_acquirer_id lookup+ // Priority logic: Use acquirer_details from request if explicitly supplied.+ // If profile_acquirer_id is provided instead, we defer acquirer resolution to+ // authentication_eligibility_core where the card network becomes available via the card number.let (acquirer_bin, acquirer_merchant_id, acquirer_country_code) =if let Some(acquirer_details) = &req.acquirer_details {- // Priority 1: Use acquirer_details from request if present(acquirer_details.acquirer_bin.clone(),acquirer_details.acquirer_merchant_id.clone(),acquirer_details.merchant_country_code.clone(),)} else {- // Priority 2: Fallback to profile_acquirer_id lookup- let acquirer_details = req.profile_acquirer_id.clone().and_then(|acquirer_id| {- business_profile- .acquirer_config_map- .and_then(|acquirer_config_map| {- acquirer_config_map.0.get(&acquirer_id).cloned()- })- });-- acquirer_details- .as_ref()- .map(|details| {- (- Some(details.acquirer_bin.clone()),- Some(details.acquirer_assigned_merchant_id.clone()),- business_profile- .merchant_country_code- .map(|code| code.get_country_code().to_owned()),- )- })- .unwrap_or((None, None, None))+ // profile_acquirer_id path: do NOT resolve here — network is unknown.+ // The profile_acquirer_id is saved on the Authentication record and resolved later.+ (None, None, None)};let customer_details = req@@ -1143,39 +1126,143 @@ pub async fn authentication_eligibility_core(.ok_or(ApiErrorResponse::InternalServerError).attach_printable("no amount found in authentication table")?;- let acquirer_details = authentication- .profile_acquirer_id- .clone()- .and_then(|acquirer_id| {- business_profile- .acquirer_config_map- .and_then(|acquirer_config_map| acquirer_config_map.0.get(&acquirer_id).cloned())- });+ let (acquirer_bin, acquirer_merchant_id, acquirer_country_code, merchant_name) =+ if authentication.acquirer_bin.is_none() || authentication.acquirer_merchant_id.is_none() {+ // Determine the card network for bucket resolution.+ let mut card_network = match &payment_method_data {+ domain::PaymentMethodData::Card(card) => card.card_network.clone(),+ domain::PaymentMethodData::CardWithOptionalCVC(card) => card.card_network.clone(),+ domain::PaymentMethodData::CardWithNetworkTokenDetails(card) => {+ card.card_details.card_network.clone()+ }+ domain::PaymentMethodData::CardDetailsForNetworkTransactionId(card) => {+ card.card_network.clone()+ }+ _ => None,+ };++ if card_network.is_none() {+ let card_isin = match &payment_method_data {+ domain::PaymentMethodData::Card(card) => Some(card.card_number.get_card_isin()),+ domain::PaymentMethodData::CardWithOptionalCVC(card) => {+ Some(card.card_number.get_card_isin())+ }+ domain::PaymentMethodData::CardWithNetworkTokenDetails(card) => {+ Some(card.card_details.card_number.get_card_isin())+ }+ domain::PaymentMethodData::CardDetailsForNetworkTransactionId(card) => {+ Some(card.card_number.get_card_isin())+ }+ _ => None,+ };++ if let Some(isin) = card_isin {+ if let Ok(Some(card_info)) = db.get_card_info(&isin).await {+ card_network = card_info.card_network;+ }+ }+ }++ let card_network = card_network+ .get_required_value("card_network")+ .change_context(ApiErrorResponse::MissingRequiredField {+ field_name: "card_network",+ })+ .attach_printable("Card network is mandatory for resolving acquirer details")?;++ // Priority for bucket resolution:+ // 1. profile_acquirer_id from eligibility request.+ // 2. profile_acquirer_id from authentication record (DB).+ // 3. Fallback to default bucket ONLY IF neither of the above are provided.+ let bucket_id = authentication.profile_acquirer_id.as_ref();++ let acquirer_details = match bucket_id {+ Some(acquirer_id) => business_profile+ .get_acquirer_details_for_profile_acquirer(acquirer_id, card_network.clone())+ .ok_or_else(|| {+ error_stack::report!(ApiErrorResponse::GenericNotFoundError {+ message: format!(+ "Configuration for network {} not found for bucket {}",+ card_network,+ acquirer_id.get_string_repr()+ ),+ })+ .attach_printable(+ "The requested profile acquirer bucket does not contain the required card network configuration",+ )+ })?,+ None => business_profile+ .get_default_acquirer_details_from_network(card_network)+ .ok_or_else(|| {+ error_stack::report!(ApiErrorResponse::GenericNotFoundError {+ message: "Default Profile Acquirer configuration not found".to_string(),+ })+ .attach_printable(+ "No default acquirer configuration was found for the given card network",+ )+ })?,+ };++ // If we resolved acquirer details from a bucket, persist them to the authentication record.+ let key_manager_state_ref = &key_manager_state;+ db.update_authentication_by_merchant_id_authentication_id(+ authentication.clone(),+ hyperswitch_domain_models::authentication::AuthenticationUpdate::AcquirerDetailsUpdate {+ acquirer_bin: acquirer_details.acquirer_bin.clone(),+ acquirer_merchant_id: acquirer_details.acquirer_assigned_merchant_id.clone(),+ acquirer_country_code: acquirer_details.acquirer_country_code.clone(),+ },+ platform.get_processor().get_key_store(),+ key_manager_state_ref,+ )+ .await+ .change_context(ApiErrorResponse::InternalServerError)+ .attach_printable("Failed to persist resolved acquirer details to authentication record")?;++ (+ acquirer_details.acquirer_bin.clone(),+ acquirer_details.acquirer_assigned_merchant_id.clone(),+ acquirer_details.acquirer_country_code.clone(),+ acquirer_details.merchant_name.clone(),+ )+ } else {+ (+ authentication.acquirer_bin.clone(),+ authentication.acquirer_merchant_id.clone(),+ authentication.acquirer_country_code.clone(),+ None,+ )+ };let metadata: Option<ThreeDsMetaData> = three_ds_connector_account.get_metadata().map(|metadata| {- metadata.expose().parse_value("ThreeDsMetaData").inspect_err(|err| {- router_env::logger::warn!(parsing_error=?err,"Error while parsing ThreeDsMetaData");- })+ metadata+ .expose()+ .parse_value("ThreeDsMetaData")+ .inspect_err(|err| {+ router_env::logger::warn!(parsing_error=?err,"Error while parsing ThreeDsMetaData");+ })}).transpose().change_context(ApiErrorResponse::InternalServerError)?;- let merchant_country_code = authentication.acquirer_country_code.clone();+ let merchant_country_code = business_profile+ .merchant_country_code+ .or(acquirer_country_code.map(common_types::payments::MerchantCountryCode::new));let merchant_category_code = business_profile.merchant_category_code.or(metadata.clone().and_then(|metadata| metadata.merchant_category_code));let merchant_details = Some(hyperswitch_domain_models::router_request_types::unified_authentication_service::MerchantDetails {merchant_id: Some(authentication.merchant_id.get_string_repr().to_string()),- merchant_name: acquirer_details.clone().map(|detail| detail.merchant_name.clone()).or(metadata.clone().and_then(|metadata| metadata.merchant_name)),+ merchant_name: merchant_name.or(metadata.clone().and_then(|metadata| metadata.merchant_name)),merchant_category_code: merchant_category_code.clone(),endpoint_prefix: metadata.clone().and_then(|metadata| metadata.endpoint_prefix),- three_ds_requestor_url: business_profile.authentication_connector_details.map(|details| details.three_ds_requestor_url),+ three_ds_requestor_url: business_profile.authentication_connector_details.as_ref().map(|details| details.three_ds_requestor_url.clone()),three_ds_requestor_id: metadata.clone().and_then(|metadata| metadata.three_ds_requestor_id),three_ds_requestor_name: metadata.clone().and_then(|metadata| metadata.three_ds_requestor_name),- merchant_country_code: merchant_country_code.clone().map(common_types::payments::MerchantCountryCode::new),+ merchant_country_code: merchant_country_code.clone(),notification_url,webhook_url:None});@@ -1202,8 +1289,10 @@ pub async fn authentication_eligibility_core(None,merchant_details.as_ref(),domain_address.as_ref(),- authentication.acquirer_bin.clone(),- authentication.acquirer_merchant_id.clone(),+ // Prefer the freshly-resolved acquirer_bin; fall back to what was already in DB.+ acquirer_bin.or_else(|| authentication.acquirer_bin.clone()),+ // Prefer the freshly-resolved acquirer_merchant_id; fall back to DB value.+ acquirer_merchant_id.or_else(|| authentication.acquirer_merchant_id.clone()),Some(routing_region),).await?;@@ -1228,9 +1317,7 @@ pub async fn authentication_eligibility_core(req.browser_information.clone(),None,merchant_category_code,- merchant_country_code- .clone()- .map(common_types::payments::MerchantCountryCode::new),+ merchant_country_code.clone(),)).await?;diff --git a/crates/router/src/db/authentication.rs b/crates/router/src/db/authentication.rsindex 564bb06670..7cc6f17982 100644--- a/crates/router/src/db/authentication.rs+++ b/crates/router/src/db/authentication.rs@@ -501,6 +501,15 @@ impl AuthenticationInterface for MockDb {auth_to_update.trans_status = Some(trans_status);auth_to_update.authentication_status = authentication_status;}+ hyperswitch_domain_models::authentication::AuthenticationUpdate::AcquirerDetailsUpdate {+ acquirer_bin,+ acquirer_merchant_id,+ acquirer_country_code,+ } => {+ auth_to_update.acquirer_bin = acquirer_bin;+ auth_to_update.acquirer_merchant_id = acquirer_merchant_id;+ auth_to_update.acquirer_country_code = acquirer_country_code;+ }}auth_to_update.modified_at = common_utils::date_time::now();diff --git a/crates/router/src/services/kafka/payment_intent.rs b/crates/router/src/services/kafka/payment_intent.rsindex 9826a8931b..4d9785534c 100644--- a/crates/router/src/services/kafka/payment_intent.rs+++ b/crates/router/src/services/kafka/payment_intent.rs@@ -246,6 +246,7 @@ impl<'a> KafkaPaymentIntent<'a> {is_iframe_redirection_enabled,is_payment_id_from_merchant,enable_partial_authorization,+ profile_acquirer_id: _,} = intent;Self {diff --git a/crates/router/src/services/kafka/payment_intent_event.rs b/crates/router/src/services/kafka/payment_intent_event.rsindex 77bbe5a893..5d9dd1fedd 100644--- a/crates/router/src/services/kafka/payment_intent_event.rs+++ b/crates/router/src/services/kafka/payment_intent_event.rs@@ -260,6 +260,7 @@ impl<'a> KafkaPaymentIntentEvent<'a> {is_iframe_redirection_enabled,is_payment_id_from_merchant,enable_partial_authorization,+ profile_acquirer_id: _,} = intent;Self {diff --git a/crates/router/src/types/api/admin.rs b/crates/router/src/types/api/admin.rsindex e46fbb5768..e271b63608 100644--- a/crates/router/src/types/api/admin.rs+++ b/crates/router/src/types/api/admin.rs@@ -39,26 +39,35 @@ use crate::{#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]pub struct ProfileAcquirerConfigs {- pub acquirer_config_map: Option<common_types::domain::AcquirerConfigMap>,+ pub acquirer_config_map: Option<common_types::domain::AcquirerConfigBucket>,pub profile_id: common_utils::id_type::ProfileId,}impl From<ProfileAcquirerConfigs>- for Option<Vec<api_models::profile_acquirer::ProfileAcquirerResponse>>+ for Option<api_models::profile_acquirer::ProfileAcquirerConfigsResponse>{fn from(item: ProfileAcquirerConfigs) -> Self {item.acquirer_config_map.map(|config_map_val| {- let mut vec: Vec<_> = config_map_val.0.into_iter().collect();- vec.sort_by_key(|k| k.0.clone());- vec.into_iter()- .map(|(profile_acquirer_id, acquirer_config)| {- api_models::profile_acquirer::ProfileAcquirerResponse::from((+ let default_id = config_map_val.default_acquirer_config.clone();++ let configs = config_map_val+ .configs+ .into_iter()+ .map(|(profile_acquirer_id, acquirer_configs)| {+ (profile_acquirer_id,- &item.profile_id,- &acquirer_config,- ))+ acquirer_configs+ .iter()+ .map(api_models::profile_acquirer::AcquirerBucketConfigResponse::from)+ .collect(),+ )})- .collect::<Vec<api_models::profile_acquirer::ProfileAcquirerResponse>>()+ .collect();++ api_models::profile_acquirer::ProfileAcquirerConfigsResponse {+ default_acquirer_config: default_id,+ configs,+ }})}}@@ -249,7 +258,20 @@ impl ForeignTryFrom<domain::Profile> for ProfileResponse {is_debit_routing_enabled: Some(item.is_debit_routing_enabled),merchant_business_country: item.merchant_business_country,is_pre_network_tokenization_enabled: item.is_pre_network_tokenization_enabled,- acquirer_configs: ProfileAcquirerConfigs {+ acquirer_configs: item.acquirer_config_map.clone().map(|config_map_val| {+ let mut configs = Vec::new();+ let default_config_id = config_map_val.default_acquirer_config;+ for (acquirer_id, config_list) in config_map_val.configs {+ let is_default = default_config_id == Some(acquirer_id.clone());+ for config in config_list {+ configs.push(api_models::profile_acquirer::ProfileAcquirerResponse::from(+ (acquirer_id.clone(), &profile_id, Some(&config), is_default),+ ));+ }+ }+ configs+ }),+ acquirer_config_bucket: ProfileAcquirerConfigs {acquirer_config_map: item.acquirer_config_map.clone(),profile_id: profile_id.clone(),}diff --git a/crates/router/src/utils/user/sample_data.rs b/crates/router/src/utils/user/sample_data.rsindex 870733f622..67e5d4577c 100644--- a/crates/router/src/utils/user/sample_data.rs+++ b/crates/router/src/utils/user/sample_data.rs@@ -300,6 +300,7 @@ pub async fn generate_sample_data(partner_merchant_identifier_details: None,state_metadata: None,installment_options: None,+ profile_acquirer_id: None,};let (connector_transaction_id, processor_transaction_data) =ConnectorTransactionId::form_id_and_data(attempt_id.clone());diff --git a/migrations/2026-04-07-114347_add-profile-acquirer-id-to-payment-intent/down.sql b/migrations/2026-04-07-114347_add-profile-acquirer-id-to-payment-intent/down.sqlnew file mode 100644index 0000000000..2a575cef7a--- /dev/null+++ b/migrations/2026-04-07-114347_add-profile-acquirer-id-to-payment-intent/down.sql@@ -0,0 +1 @@+ALTER TABLE payment_intent DROP COLUMN IF EXISTS profile_acquirer_id;diff --git a/migrations/2026-04-07-114347_add-profile-acquirer-id-to-payment-intent/up.sql b/migrations/2026-04-07-114347_add-profile-acquirer-id-to-payment-intent/up.sqlnew file mode 100644index 0000000000..5b31b51526--- /dev/null+++ b/migrations/2026-04-07-114347_add-profile-acquirer-id-to-payment-intent/up.sql@@ -0,0 +1 @@+ALTER TABLE payment_intent ADD COLUMN IF NOT EXISTS profile_acquirer_id VARCHAR(64);