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

fix(payment_methods): resolve PSP tokenization issue in modular payment methods (#11588)

Shankar Singh C8c96aa513a22
diff --git a/api-reference/v2/openapi_spec_v2.json b/api-reference/v2/openapi_spec_v2.json
index 0361e5fc87..90fcc10e56 100644
--- a/api-reference/v2/openapi_spec_v2.json
+++ b/api-reference/v2/openapi_spec_v2.json
@@ -21811,6 +21811,14 @@
"type": "string",
"description": "The return url to which the customer should be redirected to after adding the payment method",
"nullable": true
+ },
+ "customer_acceptance": {
+ "allOf": [
+ {
+ "$ref": "#/components/schemas/CustomerAcceptance"
+ }
+ ],
+ "nullable": true
}
}
},
@@ -22542,8 +22550,7 @@
"description": "Request for Payment Intent Confirm",
"required": [
"payment_method_data",
- "payment_method_type",
- "payment_method_subtype"
+ "payment_method_type"
],
"properties": {
"return_url": {
@@ -22567,7 +22574,12 @@
"$ref": "#/components/schemas/PaymentMethod"
},
"payment_method_subtype": {
- "$ref": "#/components/schemas/PaymentMethodType"
+ "allOf": [
+ {
+ "$ref": "#/components/schemas/PaymentMethodType"
+ }
+ ],
+ "nullable": true
},
"shipping": {
"allOf": [
@@ -23427,8 +23439,7 @@
"amount_details",
"customer_id",
"payment_method_data",
- "payment_method_type",
- "payment_method_subtype"
+ "payment_method_type"
],
"properties": {
"amount_details": {
@@ -23620,7 +23631,12 @@
"$ref": "#/components/schemas/PaymentMethod"
},
"payment_method_subtype": {
- "$ref": "#/components/schemas/PaymentMethodType"
+ "allOf": [
+ {
+ "$ref": "#/components/schemas/PaymentMethodType"
+ }
+ ],
+ "nullable": true
},
"customer_acceptance": {
"allOf": [
diff --git a/crates/api_models/src/payment_methods.rs b/crates/api_models/src/payment_methods.rs
index 9452d1a63e..c5eaaaa28c 100644
--- a/crates/api_models/src/payment_methods.rs
+++ b/crates/api_models/src/payment_methods.rs
@@ -3937,6 +3937,10 @@ pub struct PaymentMethodSessionConfirmRequest {
/// The return url to which the customer should be redirected to after adding the payment method
#[schema(value_type = Option<String>)]
pub return_url: Option<common_utils::types::Url>,
+
+ /// Customer acceptance for mandate creation. Required for both single-use and multi-use tokenization flows.
+ #[schema(value_type = Option<CustomerAcceptance>)]
+ pub customer_acceptance: Option<common_types::payments::CustomerAcceptance>,
}
#[cfg(feature = "v2")]
diff --git a/crates/api_models/src/payments.rs b/crates/api_models/src/payments.rs
index ee24ef8681..805301df09 100644
--- a/crates/api_models/src/payments.rs
+++ b/crates/api_models/src/payments.rs
@@ -8014,8 +8014,8 @@ pub struct PaymentsConfirmIntentRequest {
pub payment_method_type: api_enums::PaymentMethod,
/// The payment method subtype to be used for the payment. This should match with the `payment_method_data` provided
- #[schema(value_type = PaymentMethodType, example = "apple_pay")]
- pub payment_method_subtype: api_enums::PaymentMethodType,
+ #[schema(value_type = Option<PaymentMethodType>, example = "apple_pay")]
+ pub payment_method_subtype: Option<api_enums::PaymentMethodType>,
/// The shipping address for the payment. This will override the shipping address provided in the create-intent request
pub shipping: Option<Address>,
@@ -8243,8 +8243,8 @@ pub struct PaymentsRequest {
pub payment_method_type: api_enums::PaymentMethod,
/// The payment method subtype to be used for the payment. This should match with the `payment_method_data` provided
- #[schema(value_type = PaymentMethodType, example = "apple_pay")]
- pub payment_method_subtype: api_enums::PaymentMethodType,
+ #[schema(value_type = Option<PaymentMethodType>, example = "apple_pay")]
+ pub payment_method_subtype: Option<api_enums::PaymentMethodType>,
/// This "CustomerAcceptance" object is passed during Payments-Confirm request, it enlists the type, time, and mode of acceptance properties related to an acceptance done by the customer. The customer_acceptance sub object is usually passed by the SDK or client.
#[schema(value_type = Option<CustomerAcceptance>)]
diff --git a/crates/diesel_models/src/business_profile.rs b/crates/diesel_models/src/business_profile.rs
index 105de2bbe5..b20771c46a 100644
--- a/crates/diesel_models/src/business_profile.rs
+++ b/crates/diesel_models/src/business_profile.rs
@@ -86,6 +86,7 @@ pub struct Profile {
pub is_l2_l3_enabled: Option<bool>,
pub network_tokenization_credentials: Option<Encryption>,
pub payment_method_blocking: Option<PaymentMethodBlockingConfig>,
+ pub default_fallback_routing: Option<pii::SecretSerdeValue>,
}
#[cfg(feature = "v1")]
@@ -151,6 +152,7 @@ pub struct ProfileNew {
pub is_l2_l3_enabled: Option<bool>,
pub network_tokenization_credentials: Option<Encryption>,
pub payment_method_blocking: Option<PaymentMethodBlockingConfig>,
+ pub default_fallback_routing: Option<pii::SecretSerdeValue>,
}
#[cfg(feature = "v1")]
@@ -217,6 +219,7 @@ pub struct ProfileUpdateInternal {
pub external_vault_connector_details: Option<ExternalVaultConnectorDetails>,
pub network_tokenization_credentials: Option<Encryption>,
pub payment_method_blocking: Option<PaymentMethodBlockingConfig>,
+ pub default_fallback_routing: Option<pii::SecretSerdeValue>,
}
#[cfg(feature = "v1")]
@@ -280,6 +283,7 @@ impl ProfileUpdateInternal {
billing_processor_id,
network_tokenization_credentials,
payment_method_blocking,
+ default_fallback_routing,
} = self;
Profile {
profile_id: source.profile_id,
@@ -378,6 +382,7 @@ impl ProfileUpdateInternal {
network_tokenization_credentials: network_tokenization_credentials
.or(source.network_tokenization_credentials),
payment_method_blocking: payment_method_blocking.or(source.payment_method_blocking),
+ default_fallback_routing: default_fallback_routing.or(source.default_fallback_routing),
}
}
}
@@ -450,12 +455,12 @@ pub struct Profile {
pub is_l2_l3_enabled: Option<bool>,
pub network_tokenization_credentials: Option<Encryption>,
pub payment_method_blocking: Option<PaymentMethodBlockingConfig>,
+ pub default_fallback_routing: Option<pii::SecretSerdeValue>,
pub routing_algorithm_id: Option<common_utils::id_type::RoutingId>,
pub order_fulfillment_time: Option<i64>,
pub order_fulfillment_time_origin: Option<common_enums::OrderFulfillmentTimeOrigin>,
pub frm_routing_algorithm_id: Option<String>,
pub payout_routing_algorithm_id: Option<common_utils::id_type::RoutingId>,
- pub default_fallback_routing: Option<pii::SecretSerdeValue>,
pub three_ds_decision_manager_config: Option<common_types::payments::DecisionManagerRecord>,
pub should_collect_cvv_during_payment:
Option<primitive_wrappers::ShouldCollectCvvDuringPayment>,
@@ -524,11 +529,11 @@ pub struct ProfileNew {
pub merchant_country_code: Option<common_types::payments::MerchantCountryCode>,
pub billing_processor_id: Option<common_utils::id_type::MerchantConnectorAccountId>,
pub routing_algorithm_id: Option<common_utils::id_type::RoutingId>,
+ pub default_fallback_routing: Option<pii::SecretSerdeValue>,
pub order_fulfillment_time: Option<i64>,
pub order_fulfillment_time_origin: Option<common_enums::OrderFulfillmentTimeOrigin>,
pub frm_routing_algorithm_id: Option<String>,
pub payout_routing_algorithm_id: Option<common_utils::id_type::RoutingId>,
- pub default_fallback_routing: Option<pii::SecretSerdeValue>,
pub three_ds_decision_manager_config: Option<common_types::payments::DecisionManagerRecord>,
pub should_collect_cvv_during_payment:
Option<primitive_wrappers::ShouldCollectCvvDuringPayment>,
diff --git a/crates/diesel_models/src/payment_attempt.rs b/crates/diesel_models/src/payment_attempt.rs
index 9f6aec80bb..0f0b297d97 100644
--- a/crates/diesel_models/src/payment_attempt.rs
+++ b/crates/diesel_models/src/payment_attempt.rs
@@ -168,7 +168,7 @@ pub struct PaymentAttempt {
#[diesel(deserialize_as = RequiredFromNullable<storage_enums::PaymentMethod>)]
pub payment_method_type_v2: storage_enums::PaymentMethod,
pub connector_payment_id: Option<ConnectorTransactionId>,
- pub payment_method_subtype: storage_enums::PaymentMethodType,
+ pub payment_method_subtype: Option<storage_enums::PaymentMethodType>,
pub routing_result: Option<serde_json::Value>,
pub authentication_applied: Option<common_enums::AuthenticationType>,
pub external_reference_id: Option<String>,
@@ -427,7 +427,7 @@ pub struct PaymentAttemptNew {
pub feature_metadata: Option<PaymentAttemptFeatureMetadata>,
pub payment_method_type_v2: storage_enums::PaymentMethod,
pub connector_payment_id: Option<ConnectorTransactionId>,
- pub payment_method_subtype: storage_enums::PaymentMethodType,
+ pub payment_method_subtype: Option<storage_enums::PaymentMethodType>,
pub id: id_type::GlobalAttemptId,
pub connector_token_details: Option<ConnectorTokenDetails>,
pub card_discovery: Option<storage_enums::CardDiscovery>,
diff --git a/crates/diesel_models/src/schema.rs b/crates/diesel_models/src/schema.rs
index 82bce7d926..a2202739ac 100644
--- a/crates/diesel_models/src/schema.rs
+++ b/crates/diesel_models/src/schema.rs
@@ -301,6 +301,7 @@ diesel::table! {
is_l2_l3_enabled -> Nullable<Bool>,
network_tokenization_credentials -> Nullable<Bytea>,
payment_method_blocking -> Nullable<Jsonb>,
+ default_fallback_routing -> Nullable<Jsonb>,
}
}
diff --git a/crates/diesel_models/src/schema_v2.rs b/crates/diesel_models/src/schema_v2.rs
index 47a5cdb060..827d6d3ba2 100644
--- a/crates/diesel_models/src/schema_v2.rs
+++ b/crates/diesel_models/src/schema_v2.rs
@@ -296,6 +296,7 @@ diesel::table! {
is_l2_l3_enabled -> Nullable<Bool>,
network_tokenization_credentials -> Nullable<Bytea>,
payment_method_blocking -> Nullable<Jsonb>,
+ default_fallback_routing -> Nullable<Jsonb>,
#[max_length = 64]
routing_algorithm_id -> Nullable<Varchar>,
order_fulfillment_time -> Nullable<Int8>,
@@ -304,7 +305,6 @@ diesel::table! {
frm_routing_algorithm_id -> Nullable<Varchar>,
#[max_length = 64]
payout_routing_algorithm_id -> Nullable<Varchar>,
- default_fallback_routing -> Nullable<Jsonb>,
three_ds_decision_manager_config -> Nullable<Jsonb>,
should_collect_cvv_during_payment -> Nullable<Bool>,
revenue_recovery_retry_algorithm_type -> Nullable<RevenueRecoveryAlgorithmType>,
@@ -1115,7 +1115,7 @@ diesel::table! {
#[max_length = 128]
connector_payment_id -> Nullable<Varchar>,
#[max_length = 64]
- payment_method_subtype -> Varchar,
+ payment_method_subtype -> Nullable<Varchar>,
routing_result -> Nullable<Jsonb>,
authentication_applied -> Nullable<AuthenticationType>,
#[max_length = 128]
diff --git a/crates/hyperswitch_domain_models/src/business_profile.rs b/crates/hyperswitch_domain_models/src/business_profile.rs
index f39361ea8b..7a8f193b8d 100644
--- a/crates/hyperswitch_domain_models/src/business_profile.rs
+++ b/crates/hyperswitch_domain_models/src/business_profile.rs
@@ -93,6 +93,7 @@ pub struct Profile {
pub billing_processor_id: Option<common_utils::id_type::MerchantConnectorAccountId>,
pub network_tokenization_credentials: OptionalEncryptableValue,
pub payment_method_blocking: Option<PaymentMethodBlockingConfig>,
+ pub default_fallback_routing: Option<pii::SecretSerdeValue>,
}
#[cfg(feature = "v1")]
@@ -253,6 +254,7 @@ pub struct ProfileSetter {
pub billing_processor_id: Option<common_utils::id_type::MerchantConnectorAccountId>,
pub network_tokenization_credentials: OptionalEncryptableValue,
pub payment_method_blocking: Option<PaymentMethodBlockingConfig>,
+ pub default_fallback_routing: Option<pii::SecretSerdeValue>,
}
#[cfg(feature = "v1")]
@@ -323,6 +325,7 @@ impl From<ProfileSetter> for Profile {
billing_processor_id: value.billing_processor_id,
network_tokenization_credentials: value.network_tokenization_credentials,
payment_method_blocking: value.payment_method_blocking,
+ default_fallback_routing: value.default_fallback_routing,
}
}
}
@@ -426,6 +429,9 @@ pub enum ProfileUpdate {
AcquirerConfigMapUpdate {
acquirer_config_map: Option<common_types::domain::AcquirerConfigMap>,
},
+ DefaultRoutingFallbackUpdate {
+ default_fallback_routing: Option<pii::SecretSerdeValue>,
+ },
}
#[cfg(feature = "v1")]
@@ -558,6 +564,7 @@ impl From<ProfileUpdate> for ProfileUpdateInternal {
network_tokenization_credentials: network_tokenization_credentials
.map(Encryption::from),
payment_method_blocking,
+ default_fallback_routing: None,
}
}
ProfileUpdate::RoutingAlgorithmUpdate {
@@ -622,6 +629,7 @@ impl From<ProfileUpdate> for ProfileUpdateInternal {
is_l2_l3_enabled: None,
network_tokenization_credentials: None,
payment_method_blocking: None,
+ default_fallback_routing: None,
},
ProfileUpdate::DynamicRoutingAlgorithmUpdate {
dynamic_routing_algorithm,
@@ -683,6 +691,7 @@ impl From<ProfileUpdate> for ProfileUpdateInternal {
is_l2_l3_enabled: None,
network_tokenization_credentials: None,
payment_method_blocking: None,
+ default_fallback_routing: None,
},
ProfileUpdate::ExtendedCardInfoUpdate {
is_extended_card_info_enabled,
@@ -744,6 +753,7 @@ impl From<ProfileUpdate> for ProfileUpdateInternal {
is_l2_l3_enabled: None,
network_tokenization_credentials: None,
payment_method_blocking: None,
+ default_fallback_routing: None,
},
ProfileUpdate::ConnectorAgnosticMitUpdate {
is_connector_agnostic_mit_enabled,
@@ -805,6 +815,7 @@ impl From<ProfileUpdate> for ProfileUpdateInternal {
is_l2_l3_enabled: None,
network_tokenization_credentials: None,
payment_method_blocking: None,
+ default_fallback_routing: None,
},
ProfileUpdate::NetworkTokenizationUpdate {
is_network_tokenization_enabled,
@@ -868,6 +879,7 @@ impl From<ProfileUpdate> for ProfileUpdateInternal {
network_tokenization_credentials: network_tokenization_credentials
.map(Encryption::from),
payment_method_blocking: None,
+ default_fallback_routing: None,
},
ProfileUpdate::CardTestingSecretKeyUpdate {
card_testing_secret_key,
@@ -929,6 +941,7 @@ impl From<ProfileUpdate> for ProfileUpdateInternal {
is_l2_l3_enabled: None,
network_tokenization_credentials: None,
payment_method_blocking: None,
+ default_fallback_routing: None,
},
ProfileUpdate::AcquirerConfigMapUpdate {
acquirer_config_map,
@@ -990,6 +1003,69 @@ impl From<ProfileUpdate> for ProfileUpdateInternal {
is_l2_l3_enabled: None,
network_tokenization_credentials: None,
payment_method_blocking: None,
+ default_fallback_routing: None,
+ },
+ ProfileUpdate::DefaultRoutingFallbackUpdate {
+ default_fallback_routing,
+ } => Self {
+ profile_name: None,
+ modified_at: now,
+ return_url: None,
+ enable_payment_response_hash: None,
+ payment_response_hash_key: None,
+ redirect_to_merchant_with_http_post: None,
+ webhook_details: None,
+ metadata: None,
+ routing_algorithm: None,
+ intent_fulfillment_time: None,
+ frm_routing_algorithm: None,
+ payout_routing_algorithm: None,
+ is_recon_enabled: None,
+ applepay_verified_domains: None,
+ payment_link_config: None,
+ session_expiry: None,
+ authentication_connector_details: None,
+ payout_link_config: None,
+ is_extended_card_info_enabled: None,
+ extended_card_info_config: None,
+ is_connector_agnostic_mit_enabled: None,
+ use_billing_as_payment_method_billing: None,
+ collect_shipping_details_from_wallet_connector: None,
+ collect_billing_details_from_wallet_connector: None,
+ outgoing_webhook_custom_http_headers: None,
+ always_collect_billing_details_from_wallet_connector: None,
+ always_collect_shipping_details_from_wallet_connector: None,
+ tax_connector_id: None,
+ is_tax_connector_enabled: None,
+ dynamic_routing_algorithm: None,
+ is_network_tokenization_enabled: None,
+ is_auto_retries_enabled: None,
+ max_auto_retries_enabled: None,
+ always_request_extended_authorization: None,
+ is_click_to_pay_enabled: None,
+ authentication_product_ids: None,
+ card_testing_guard_config: None,
+ card_testing_secret_key: None,
+ is_clear_pan_retries_enabled: None,
+ force_3ds_challenge: None,
+ is_debit_routing_enabled: None,
+ merchant_business_country: None,
+ is_iframe_redirection_enabled: None,
+ is_pre_network_tokenization_enabled: None,
+ three_ds_decision_rule_algorithm: None,
+ acquirer_config_map: None,
+ merchant_category_code: None,
+ merchant_country_code: None,
+ dispute_polling_interval: None,
+ is_manual_retry_enabled: None,
+ always_enable_overcapture: None,
+ is_external_vault_enabled: None,
+ external_vault_connector_details: None,
+ billing_processor_id: None,
+ is_l2_l3_enabled: None,
+ payment_method_blocking: None,
+ default_fallback_routing,
+ network_tokenization_credentials: None,
},
}
}
@@ -1076,6 +1152,7 @@ impl Conversion for Profile {
.network_tokenization_credentials
.map(|name| name.into()),
payment_method_blocking: self.payment_method_blocking,
+ default_fallback_routing: self.default_fallback_routing,
})
}
@@ -1223,6 +1300,7 @@ impl Conversion for Profile {
billing_processor_id: item.billing_processor_id,
network_tokenization_credentials,
payment_method_blocking: item.payment_method_blocking,
+ default_fallback_routing: item.default_fallback_routing,
})
}
@@ -1296,6 +1374,7 @@ impl Conversion for Profile {
.network_tokenization_credentials
.map(|name| name.into()),
payment_method_blocking: self.payment_method_blocking,
+ default_fallback_routing: self.default_fallback_routing,
})
}
}
diff --git a/crates/hyperswitch_domain_models/src/payments.rs b/crates/hyperswitch_domain_models/src/payments.rs
index cd12ae6ed1..f0e9533aa3 100644
--- a/crates/hyperswitch_domain_models/src/payments.rs
+++ b/crates/hyperswitch_domain_models/src/payments.rs
@@ -51,6 +51,7 @@ use error_stack::ResultExt;
use hyperswitch_masking::ExposeInterface;
use self::{payment_attempt::PaymentAttempt, payment_intent::CustomerData};
+use crate::ext_traits::OptionExt;
#[cfg(feature = "v2")]
use crate::{
address::Address, business_profile, customer, errors, merchant_connector_account,
@@ -59,7 +60,7 @@ use crate::{
ApiModelToDieselModelConvertor,
};
#[cfg(feature = "v1")]
-use crate::{errors, ext_traits::OptionExt, payment_method_data, RemoteStorageObject};
+use crate::{errors, payment_method_data, RemoteStorageObject};
#[cfg(feature = "v1")]
#[derive(Clone, Debug, PartialEq, serde::Serialize, ToEncryption)]
@@ -595,7 +596,7 @@ impl AmountDetails {
let order_tax_amount = match self.skip_external_tax_calculation {
common_enums::TaxCalculationOverride::Skip => {
self.tax_details.as_ref().and_then(|tax_details| {
- tax_details.get_tax_amount(Some(confirm_intent_request.payment_method_subtype))
+ tax_details.get_tax_amount(confirm_intent_request.payment_method_subtype)
})
}
common_enums::TaxCalculationOverride::Calculate => None,
@@ -649,7 +650,7 @@ impl AmountDetails {
let order_tax_amount = match self.skip_external_tax_calculation {
common_enums::TaxCalculationOverride::Skip => {
self.tax_details.as_ref().and_then(|tax_details| {
- tax_details.get_tax_amount(Some(confirm_intent_request.payment_method_subtype))
+ tax_details.get_tax_amount(confirm_intent_request.payment_method_subtype)
})
}
common_enums::TaxCalculationOverride::Calculate => None,
@@ -1483,7 +1484,14 @@ where
.clone(),
},
payment_method_type: self.payment_attempt.payment_method_type,
- payment_method_subtype: self.payment_attempt.payment_method_subtype,
+ payment_method_subtype: self
+ .payment_attempt
+ .payment_method_subtype
+ .get_required_value("payment_method_subtype")
+ .change_context(
+ errors::api_error_response::ApiErrorResponse::InternalServerError,
+ )
+ .attach_printable("Failed to construct revenue recovery metadata")?,
connector: connector.parse().map_err(|err| {
router_env::logger::error!(?err, "Failed to parse connector string to enum");
errors::api_error_response::ApiErrorResponse::InternalServerError
diff --git a/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs b/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs
index f07dcb283f..5f4ddb529c 100644
--- a/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs
+++ b/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs
@@ -804,7 +804,7 @@ pub struct PaymentAttempt {
/// The reference to the payment at the connector side
pub connector_payment_id: Option<String>,
/// The payment method subtype for the payment attempt.
- pub payment_method_subtype: storage_enums::PaymentMethodType,
+ pub payment_method_subtype: Option<storage_enums::PaymentMethodType>,
/// The authentication type that was applied for the payment attempt.
pub authentication_applied: Option<common_enums::AuthenticationType>,
/// A reference to the payment at connector side. This is returned by the connector
@@ -851,8 +851,7 @@ impl PaymentAttempt {
#[cfg(feature = "v2")]
pub fn get_payment_method_type(&self) -> Option<storage_enums::PaymentMethodType> {
- // TODO: check if we can fix this
- Some(self.payment_method_subtype)
+ self.payment_method_subtype
}
#[cfg(feature = "v1")]
@@ -1074,8 +1073,7 @@ impl PaymentAttempt {
.unwrap_or(common_enums::PaymentMethod::Card),
payment_method_id: None,
connector_payment_id: None,
- payment_method_subtype: payment_method_subtype_data
- .unwrap_or(common_enums::PaymentMethodType::Credit),
+ payment_method_subtype: payment_method_subtype_data,
authentication_applied: None,
external_reference_id: None,
payment_method_billing_address,
@@ -1174,8 +1172,7 @@ impl PaymentAttempt {
.unwrap_or(common_enums::PaymentMethod::Card),
payment_method_id: request.payment_method_id.clone(),
connector_payment_id: None,
- payment_method_subtype: payment_method_subtype_data
- .unwrap_or(common_enums::PaymentMethodType::Credit),
+ payment_method_subtype: payment_method_subtype_data,
authentication_applied: None,
external_reference_id: None,
payment_method_billing_address,
@@ -1295,7 +1292,7 @@ impl PaymentAttempt {
payment_method_type: request.payment_method_type,
payment_method_id: None,
connector_payment_id,
- payment_method_subtype: request.payment_method_subtype,
+ payment_method_subtype: Some(request.payment_method_subtype),
authentication_applied: None,
external_reference_id: None,
payment_method_billing_address,
@@ -1678,22 +1675,23 @@ impl PaymentAttempt {
match (self.payment_method_type, self.payment_method_subtype) {
(
storage_enums::PaymentMethod::Upi,
- storage_enums::PaymentMethodType::UpiIntent,
+ Some(storage_enums::PaymentMethodType::UpiIntent),
) => sdk_uri_opt
.zip(wait_screen_info)
.map(|(sdk_uri, wait_info)| {
api_models::payments::NextActionData::from_upi_intent(sdk_uri, wait_info)
}),
- (storage_enums::PaymentMethod::Upi, storage_enums::PaymentMethodType::UpiQr) => {
- sdk_uri_opt
- .zip(wait_screen_info)
- .map(|(sdk_uri, wait_info)| {
- api_models::payments::NextActionData::from_upi_qr(sdk_uri, wait_info)
- })
- }
(
storage_enums::PaymentMethod::Upi,
- storage_enums::PaymentMethodType::UpiCollect,
+ Some(storage_enums::PaymentMethodType::UpiQr),
+ ) => sdk_uri_opt
+ .zip(wait_screen_info)
+ .map(|(sdk_uri, wait_info)| {
+ api_models::payments::NextActionData::from_upi_qr(sdk_uri, wait_info)
+ }),
+ (
+ storage_enums::PaymentMethod::Upi,
+ Some(storage_enums::PaymentMethodType::UpiCollect),
) => wait_screen_info.map(api_models::payments::NextActionData::from_wait_screen),
_ => None,
},
diff --git a/crates/router/src/core/admin.rs b/crates/router/src/core/admin.rs
index 51f2ec0a6c..6a9ab4c734 100644
--- a/crates/router/src/core/admin.rs
+++ b/crates/router/src/core/admin.rs
@@ -1684,6 +1684,8 @@ struct MerchantDefaultConfigUpdate<'a> {
merchant_id: &'a id_type::MerchantId,
profile_id: &'a id_type::ProfileId,
transaction_type: &'a api_enums::TransactionType,
+ business_profile: &'a domain::Profile,
+ key_store: &'a domain::MerchantKeyStore,
}
#[cfg(feature = "v1")]
impl MerchantDefaultConfigUpdate<'_> {
@@ -1721,7 +1723,7 @@ impl MerchantDefaultConfigUpdate<'_> {
.await?;
}
if !default_routing_config_for_profile.contains(&choice.clone()) {
- default_routing_config_for_profile.push(choice);
+ default_routing_config_for_profile.push(choice.clone());
routing::helpers::update_merchant_default_config(
self.store,
self.profile_id.get_string_repr(),
@@ -1730,6 +1732,44 @@ impl MerchantDefaultConfigUpdate<'_> {
)
.await?;
}
+ // Update the business_profile.default_fallback_routing column
+ let mut profile_fallback_config = if let Some(default_fallback_routing) =
+ &self.business_profile.default_fallback_routing
+ {
+ default_fallback_routing
+ .clone()
+ .expose()
+ .parse_value::<Vec<routing_types::RoutableConnectorChoice>>(
+ "Vec<RoutableConnectorChoice>",
+ )
+ .change_context(errors::ApiErrorResponse::InternalServerError)
+ .attach_printable("Business Profile default config has invalid structure")?
+ } else {
+ Vec::new()
+ };
+ if !profile_fallback_config.contains(&choice) {
+ profile_fallback_config.push(choice);
+ let default_fallback_routing = Secret::from(
+ profile_fallback_config
+ .encode_to_value()
+ .change_context(errors::ApiErrorResponse::InternalServerError)
+ .attach_printable("Failed to convert routing ref to value")?,
+ );
+ let profile_update = domain::ProfileUpdate::DefaultRoutingFallbackUpdate {
+ default_fallback_routing: Some(default_fallback_routing),
+ };
+ self.store
+ .update_profile_by_profile_id(
+ self.key_store,
+ self.business_profile.clone(),
+ profile_update,
+ )
+ .await
+ .change_context(errors::ApiErrorResponse::InternalServerError)
+ .attach_printable(
+ "Failed to update routing algorithm ref in business profile",
+ )?;
+ }
}
Ok(())
}
@@ -1781,6 +1821,46 @@ impl MerchantDefaultConfigUpdate<'_> {
)
.await?;
}
+ // Update the business_profile.default_fallback_routing column
+ let mut profile_fallback_config = if let Some(default_fallback_routing) =
+ &self.business_profile.default_fallback_routing
+ {
+ default_fallback_routing
+ .clone()
+ .expose()
+ .parse_value::<Vec<routing_types::RoutableConnectorChoice>>(
+ "Vec<RoutableConnectorChoice>",
+ )
+ .change_context(errors::ApiErrorResponse::InternalServerError)
+ .attach_printable("Business Profile default config has invalid structure")?
+ } else {
+ Vec::new()
+ };
+ if profile_fallback_config.contains(&choice) {
+ profile_fallback_config.retain(|mca| {
+ mca.merchant_connector_id.as_ref() != Some(self.merchant_connector_id)
+ });
+ let default_fallback_routing = Secret::from(
+ profile_fallback_config
+ .encode_to_value()
+ .change_context(errors::ApiErrorResponse::InternalServerError)
+ .attach_printable("Failed to convert routing ref to value")?,
+ );
+ let profile_update = domain::ProfileUpdate::DefaultRoutingFallbackUpdate {
+ default_fallback_routing: Some(default_fallback_routing),
+ };
+ self.store
+ .update_profile_by_profile_id(
+ self.key_store,
+ self.business_profile.clone(),
+ profile_update,
+ )
+ .await
+ .change_context(errors::ApiErrorResponse::InternalServerError)
+ .attach_printable(
+ "Failed to update routing algorithm ref in business profile",
+ )?;
+ }
}
Ok(())
}
@@ -2732,6 +2812,8 @@ pub async fn create_connector(
merchant_id,
profile_id: business_profile.get_id(),
transaction_type: &req.get_transaction_type(),
+ business_profile: &business_profile,
+ key_store: processor.get_key_store(),
};
#[cfg(feature = "v2")]
@@ -2982,6 +3064,15 @@ pub async fn update_connector(
// redact cgraph cache on connector updation
redact_cgraph_cache(&state, &merchant_id, &profile_id).await?;
+ // Fetch business profile for routing update
+ #[cfg(feature = "v1")]
+ let business_profile = db
+ .find_business_profile_by_profile_id(&key_store, &mca.profile_id)
+ .await
+ .to_not_found_response(errors::ApiErrorResponse::ProfileNotFound {
+ id: mca.profile_id.get_string_repr().to_owned(),
+ })?;
+
// redact routing cache on connector updation
#[cfg(feature = "v1")]
let merchant_config = MerchantDefaultConfigUpdate {
@@ -2997,6 +3088,8 @@ pub async fn update_connector(
merchant_id: &merchant_id,
profile_id: &mca.profile_id,
transaction_type: &mca.connector_type.into(),
+ business_profile: &business_profile,
+ key_store: &key_store,
};
#[cfg(feature = "v1")]
@@ -3053,6 +3146,14 @@ pub async fn delete_connector(
id: merchant_connector_id.get_string_repr().to_string(),
})?;
+ // Fetch business profile for routing update
+ let business_profile = db
+ .find_business_profile_by_profile_id(&key_store, &mca.profile_id)
+ .await
+ .to_not_found_response(errors::ApiErrorResponse::ProfileNotFound {
+ id: mca.profile_id.get_string_repr().to_owned(),
+ })?;
+
// delete the mca from the config as well
let merchant_default_config_delete = MerchantDefaultConfigUpdate {
routable_connector: &Some(
@@ -3067,6 +3168,8 @@ pub async fn delete_connector(
merchant_id: &merchant_id,
profile_id: &mca.profile_id,
transaction_type: &mca.connector_type.into(),
+ business_profile: &business_profile,
+ key_store: &key_store,
};
merchant_default_config_delete
@@ -3574,6 +3677,7 @@ impl ProfileCreateBridge for api::ProfileCreate {
is_l2_l3_enabled: self.is_l2_l3_enabled.unwrap_or(false),
network_tokenization_credentials,
payment_method_blocking: self.payment_method_blocking.map(ForeignInto::foreign_into),
+ default_fallback_routing: None,
}))
}
diff --git a/crates/router/src/core/payment_methods.rs b/crates/router/src/core/payment_methods.rs
index 1cfde71d8f..a487c30bc6 100644
--- a/crates/router/src/core/payment_methods.rs
+++ b/crates/router/src/core/payment_methods.rs
@@ -75,7 +75,7 @@ use crate::{
routes::{self, payment_methods as pm_routes},
services::encryption,
types::{
- api::PaymentMethodCreateExt,
+ api::{PaymentMethodCreateExt, PaymentMethodSessionExt},
domain::types as domain_types,
storage::{ephemeral_key, PaymentMethodListContext},
transformers::{ForeignFrom, ForeignTryFrom},
@@ -4946,8 +4946,7 @@ fn construct_zero_auth_payments_request(
),
payment_method_data: confirm_request.payment_method_data.clone(),
payment_method_type: confirm_request.payment_method_type,
- payment_method_subtype: payment_method_subtype
- .get_required_value("payment_method_subtype")?,
+ payment_method_subtype,
customer_id: payment_method_session.customer_id.clone(),
customer_present: Some(enums::PresenceOfCustomerDuringPayment::Present),
setup_future_usage: Some(common_enums::FutureUsage::OffSession),
@@ -4974,7 +4973,7 @@ fn construct_zero_auth_payments_request(
session_expiry: None,
frm_metadata: None,
request_external_three_ds_authentication: None,
- customer_acceptance: None,
+ customer_acceptance: confirm_request.customer_acceptance.clone(),
browser_info: None,
force_3ds_challenge: None,
is_iframe_redirection_enabled: None,
@@ -5021,7 +5020,6 @@ pub async fn payment_methods_session_confirm(
request: payment_methods::PaymentMethodSessionConfirmRequest,
) -> RouterResponse<payment_methods::PaymentMethodSessionResponse> {
let db: &dyn StorageInterface = state.store.as_ref();
- request.validate()?;
// Validate if the session still exists
let payment_method_session = db
@@ -5035,6 +5033,8 @@ pub async fn payment_methods_session_confirm(
})
.attach_printable("Failed to retrieve payment methods session from db")?;
+ request.validate(&payment_method_session)?;
+
let payment_method_session_billing = payment_method_session
.billing
.clone()
@@ -5148,6 +5148,7 @@ pub async fn payment_methods_session_confirm(
&create_payment_method_request.clone(),
&payment_method_response,
&payment_method_session,
+ request.customer_acceptance.clone(),
))
.await?;
None
@@ -5263,6 +5264,7 @@ async fn create_single_use_tokenization_flow(
payment_method_create_request: &payment_methods::PaymentMethodCreate,
payment_method: &api::PaymentMethodResponse,
payment_method_session: &domain::payment_methods::PaymentMethodSession,
+ customer_acceptance: Option<common_types::payments::CustomerAcceptance>,
) -> RouterResult<()> {
let customer_id = payment_method_create_request.customer_id.to_owned();
let connector_id = payment_method_create_request
@@ -5305,7 +5307,7 @@ async fn create_single_use_tokenization_flow(
split_payments: None,
mandate_id: None,
setup_future_usage: None,
- customer_acceptance: None,
+ customer_acceptance,
setup_mandate_details: None,
payment_method_type: None,
capture_method: None,
diff --git a/crates/router/src/core/payments.rs b/crates/router/src/core/payments.rs
index 638f0d452f..ab3d53c03a 100644
--- a/crates/router/src/core/payments.rs
+++ b/crates/router/src/core/payments.rs
@@ -9653,9 +9653,11 @@ where
.clone(),
pre_routing_connector_choice: payment_data.get_pre_routing_result().and_then(
|pre_routing_results| {
- pre_routing_results
- .get(&payment_data.get_payment_attempt().payment_method_subtype)
- .cloned()
+ payment_data
+ .get_payment_attempt()
+ .payment_method_subtype
+ .as_ref()
+ .and_then(|subtype| pre_routing_results.get(subtype).cloned())
},
),
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.rs
index 052483f7e5..a2ce85d5cc 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
@@ -375,9 +375,7 @@ impl<F: Clone + Send + Sync> Domain<F, ExternalVaultProxyPaymentsRequest, Paymen
let req = api::PaymentMethodCreate {
payment_method_type: payment_data.payment_attempt.payment_method_type,
- payment_method_subtype: Some(
- payment_data.payment_attempt.payment_method_subtype,
- ),
+ payment_method_subtype: payment_data.payment_attempt.payment_method_subtype,
metadata: None,
customer_id: Some(customer_id),
payment_method_data,
diff --git a/crates/router/src/core/payments/operations/payment_confirm_intent.rs b/crates/router/src/core/payments/operations/payment_confirm_intent.rs
index b5809c20e0..38f8af63fc 100644
--- a/crates/router/src/core/payments/operations/payment_confirm_intent.rs
+++ b/crates/router/src/core/payments/operations/payment_confirm_intent.rs
@@ -634,9 +634,7 @@ impl<F: Clone + Send + Sync> Domain<F, PaymentsConfirmIntentRequest, PaymentConf
let req = api::PaymentMethodCreate {
payment_method_type: payment_data.payment_attempt.payment_method_type,
- payment_method_subtype: Some(
- payment_data.payment_attempt.payment_method_subtype,
- ),
+ payment_method_subtype: payment_data.payment_attempt.payment_method_subtype,
metadata: None,
customer_id: Some(customer_id),
payment_method_data: pm_create_data,
diff --git a/crates/router/src/core/payments/operations/payment_response.rs b/crates/router/src/core/payments/operations/payment_response.rs
index 97c8552894..05ad888d17 100644
--- a/crates/router/src/core/payments/operations/payment_response.rs
+++ b/crates/router/src/core/payments/operations/payment_response.rs
@@ -3685,8 +3685,13 @@ impl<F: Clone> PostUpdateTracker<F, PaymentConfirmData<F>, types::SetupMandateRe
connector_token_details: Some(
connector_token_details_for_payment_method_update,
),
- network_transaction_id: None,
- acknowledgement_status: None, //based on the response from the connector we can decide the acknowledgement status to be sent to payment method service
+ network_transaction_id: payments_response
+ .get_network_transaction_id()
+ .map(hyperswitch_masking::Secret::new),
+ acknowledgement_status: router_data
+ .status
+ .should_update_payment_method()
+ .then_some(common_enums::AcknowledgementStatus::Authenticated),
};
let payment_method_update_request =
diff --git a/crates/router/src/core/payments/routing.rs b/crates/router/src/core/payments/routing.rs
index fa6b32cd7f..03d3843739 100644
--- a/crates/router/src/core/payments/routing.rs
+++ b/crates/router/src/core/payments/routing.rs
@@ -277,7 +277,7 @@ pub fn make_dsl_input(
};
let payment_method_input = dsl_inputs::PaymentMethodInput {
payment_method: Some(payments_dsl_input.payment_attempt.payment_method_type),
- payment_method_type: Some(payments_dsl_input.payment_attempt.payment_method_subtype),
+ payment_method_type: payments_dsl_input.payment_attempt.payment_method_subtype,
card_network: payments_dsl_input
.payment_method_data
.as_ref()
diff --git a/crates/router/src/core/payments/transformers.rs b/crates/router/src/core/payments/transformers.rs
index 65a684263f..40ab6775b6 100644
--- a/crates/router/src/core/payments/transformers.rs
+++ b/crates/router/src/core/payments/transformers.rs
@@ -449,7 +449,7 @@ pub async fn construct_payment_router_data_for_authorize<'a>(
session_token: None,
enrolled_for_3ds: true,
related_transaction_id: None,
- payment_method_type: Some(payment_data.payment_attempt.payment_method_subtype),
+ payment_method_type: payment_data.payment_attempt.payment_method_subtype,
router_return_url: Some(router_return_url),
webhook_url,
complete_authorize_url,
@@ -523,7 +523,7 @@ pub async fn construct_payment_router_data_for_authorize<'a>(
.to_owned(),
status: payment_data.payment_attempt.status,
payment_method,
- payment_method_type: Some(payment_data.payment_attempt.payment_method_subtype),
+ payment_method_type: payment_data.payment_attempt.payment_method_subtype,
connector_auth_type: auth_type,
description: payment_data
.payment_intent
@@ -706,7 +706,7 @@ pub async fn construct_external_vault_proxy_payment_router_data<'a>(
session_token: None,
enrolled_for_3ds: true,
related_transaction_id: None,
- payment_method_type: Some(payment_data.payment_attempt.payment_method_subtype),
+ payment_method_type: payment_data.payment_attempt.payment_method_subtype,
router_return_url: Some(router_return_url),
webhook_url,
complete_authorize_url,
@@ -873,7 +873,7 @@ pub async fn construct_payment_router_data_for_capture<'a>(
.to_owned(),
status: payment_data.payment_attempt.status,
payment_method,
- payment_method_type: Some(payment_data.payment_attempt.payment_method_subtype),
+ payment_method_type: payment_data.payment_attempt.payment_method_subtype,
connector_auth_type: auth_type,
description: payment_data
.payment_intent
@@ -986,7 +986,7 @@ pub async fn construct_router_data_for_psync<'a>(
capture_method: Some(payment_intent.capture_method),
connector_meta: attempt.connector_metadata.clone().expose_option(),
sync_type: types::SyncRequestType::SinglePaymentSync,
- payment_method_type: Some(attempt.payment_method_subtype),
+ payment_method_type: attempt.payment_method_subtype,
currency: payment_intent.amount_details.currency,
// TODO: Get the charges object from feature metadata
split_payments: None,
@@ -1010,7 +1010,7 @@ pub async fn construct_router_data_for_psync<'a>(
attempt_id: attempt.get_id().get_string_repr().to_owned(),
status: attempt.status,
payment_method: attempt.payment_method_type,
- payment_method_type: Some(attempt.payment_method_subtype),
+ payment_method_type: attempt.payment_method_subtype,
connector_auth_type: auth_type,
description: payment_intent
.description
@@ -1328,7 +1328,7 @@ pub async fn construct_payment_router_data_for_sdk_session<'a>(
let payment_attempt = payment_data.get_payment_attempt();
let payment_method = Some(payment_attempt.payment_method_type);
- let payment_method_type = Some(payment_attempt.payment_method_subtype);
+ let payment_method_type = payment_attempt.payment_method_subtype;
// TODO: few fields are repeated in both routerdata and request
let request = types::PaymentsSessionData {
@@ -1556,7 +1556,7 @@ pub async fn construct_payment_router_data_for_setup_mandate<'a>(
email,
customer_name: None,
return_url: Some(router_return_url),
- payment_method_type: Some(payment_data.payment_attempt.payment_method_subtype),
+ payment_method_type: payment_data.payment_attempt.payment_method_subtype,
request_incremental_authorization: matches!(
payment_data
.payment_intent
@@ -1608,7 +1608,7 @@ pub async fn construct_payment_router_data_for_setup_mandate<'a>(
.to_owned(),
status: payment_data.payment_attempt.status,
payment_method,
- payment_method_type: Some(payment_data.payment_attempt.payment_method_subtype),
+ payment_method_type: payment_data.payment_attempt.payment_method_subtype,
connector_auth_type: auth_type,
description: payment_data
.payment_intent
@@ -2421,7 +2421,7 @@ where
connector,
created: payment_intent.created_at,
payment_method_type: Some(payment_attempt.payment_method_type),
- payment_method_subtype: Some(payment_attempt.payment_method_subtype),
+ payment_method_subtype: payment_attempt.payment_method_subtype,
attempts: None,
return_url: payment_intent.return_url.clone(),
error,
@@ -2867,7 +2867,7 @@ where
modified_at: payment_intent.modified_at,
payment_method_data,
payment_method_type: Some(payment_attempt.payment_method_type),
- payment_method_subtype: Some(payment_attempt.payment_method_subtype),
+ payment_method_subtype: payment_attempt.payment_method_subtype,
next_action,
connector_transaction_id: payment_attempt.connector_payment_id.clone(),
connector_reference_id: payment_attempt.connector_response_reference_id.clone(),
@@ -3023,7 +3023,7 @@ impl GenerateResponse<api_models::payments::PaymentsResponse>
modified_at: payment_intent.modified_at,
payment_method_data,
payment_method_type: Some(payment_attempt.payment_method_type),
- payment_method_subtype: Some(payment_attempt.payment_method_subtype),
+ payment_method_subtype: payment_attempt.payment_method_subtype,
next_action,
connector_transaction_id: payment_attempt.connector_payment_id.clone(),
connector_reference_id: payment_attempt.connector_response_reference_id.clone(),
@@ -3151,7 +3151,7 @@ where
modified_at: payment_intent.modified_at,
payment_method_data,
payment_method_type: Some(payment_attempt.payment_method_type),
- payment_method_subtype: Some(payment_attempt.payment_method_subtype),
+ payment_method_subtype: payment_attempt.payment_method_subtype,
connector_transaction_id: payment_attempt.connector_payment_id.clone(),
connector_reference_id: payment_attempt.connector_response_reference_id.clone(),
merchant_connector_id,
@@ -4510,7 +4510,7 @@ impl ForeignFrom<(storage::PaymentIntent, Option<storage::PaymentAttempt>)>
)),
created: pi.created_at,
payment_method_type: pa.as_ref().and_then(|p| p.payment_method_type.into()),
- payment_method_subtype: pa.as_ref().and_then(|p| p.payment_method_subtype.into()),
+ payment_method_subtype: pa.as_ref().and_then(|p| p.payment_method_subtype),
connector: pa.as_ref().and_then(|p| p.connector.clone()),
merchant_connector_id: pa.as_ref().and_then(|p| p.merchant_connector_id.clone()),
customer: None,
@@ -4800,7 +4800,7 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::PaymentsAuthoriz
enrolled_for_3ds: false,
related_transaction_id: None,
payment_experience: None,
- payment_method_type: Some(payment_data.payment_attempt.payment_method_subtype),
+ payment_method_type: payment_data.payment_attempt.payment_method_subtype,
surcharge_details: None,
customer_id,
request_incremental_authorization: false,
@@ -5822,7 +5822,7 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::PaymentsSessionD
order_tax_amount,
shipping_cost: payment_data.payment_intent.amount_details.shipping_cost,
payment_method: Some(payment_data.payment_attempt.payment_method_type),
- payment_method_type: Some(payment_data.payment_attempt.payment_method_subtype),
+ payment_method_type: payment_data.payment_attempt.payment_method_subtype,
split_payments: payment_data.payment_intent.split_payments,
})
}
diff --git a/crates/router/src/core/revenue_recovery.rs b/crates/router/src/core/revenue_recovery.rs
index 48cbb6a187..21670e237c 100644
--- a/crates/router/src/core/revenue_recovery.rs
+++ b/crates/router/src/core/revenue_recovery.rs
@@ -1498,7 +1498,7 @@ pub fn map_to_recovery_payment_item(
.and_then(|p| p.payment_method_type.into()),
payment_method_subtype: payment_attempt
.as_ref()
- .and_then(|p| p.payment_method_subtype.into()),
+ .and_then(|p| p.payment_method_subtype),
connector: payment_attempt.as_ref().and_then(|p| p.connector.clone()),
merchant_connector_id: payment_attempt
.as_ref()
diff --git a/crates/router/src/core/revenue_recovery/types.rs b/crates/router/src/core/revenue_recovery/types.rs
index 0036565b84..8b8d7cb6c2 100644
--- a/crates/router/src/core/revenue_recovery/types.rs
+++ b/crates/router/src/core/revenue_recovery/types.rs
@@ -1544,7 +1544,7 @@ pub fn construct_invoice_record_back_router_data(
merchant_reference_id,
amount: payment_attempt.get_total_amount(),
currency: payment_intent.amount_details.currency,
- payment_method_type: Some(payment_attempt.payment_method_subtype),
+ payment_method_type: payment_attempt.payment_method_subtype,
attempt_status: payment_attempt.status,
connector_transaction_id: payment_attempt
.connector_payment_id
diff --git a/crates/router/src/core/routing.rs b/crates/router/src/core/routing.rs
index de94fc443c..41092fec37 100644
--- a/crates/router/src/core/routing.rs
+++ b/crates/router/src/core/routing.rs
@@ -18,7 +18,7 @@ use api_models::{
use async_trait::async_trait;
#[cfg(all(feature = "v1", feature = "dynamic_routing"))]
use common_utils::ext_traits::AsyncExt;
-use common_utils::request::Method;
+use common_utils::{ext_traits::Encode, request::Method};
use diesel_models::routing_algorithm::RoutingAlgorithm;
use error_stack::ResultExt;
#[cfg(all(feature = "v1", feature = "dynamic_routing"))]
@@ -32,6 +32,7 @@ use helpers::{
enable_decision_engine_dynamic_routing_setup, update_decision_engine_dynamic_routing_setup,
};
use hyperswitch_domain_models::{mandates, payment_address};
+use hyperswitch_masking::Secret;
use payment_methods::helpers::StorageErrorExt;
use rustc_hash::FxHashSet;
#[cfg(all(feature = "v1", feature = "dynamic_routing"))]
@@ -1643,6 +1644,25 @@ pub async fn update_default_routing_config_for_profile(
)
.await?;
+ // Dual-write: also update business_profile.default_fallback_routing column
+ let default_fallback_routing = Secret::from(
+ updated_config
+ .encode_to_value()
+ .change_context(errors::ApiErrorResponse::InternalServerError)
+ .attach_printable("Failed to encode updated config to value")?,
+ );
+ let profile_update = domain::ProfileUpdate::DefaultRoutingFallbackUpdate {
+ default_fallback_routing: Some(default_fallback_routing),
+ };
+ db.update_profile_by_profile_id(
+ platform.get_processor().get_key_store(),
+ business_profile.clone(),
+ profile_update,
+ )
+ .await
+ .change_context(errors::ApiErrorResponse::InternalServerError)
+ .attach_printable("Failed to update default_fallback_routing in business profile")?;
+
metrics::ROUTING_UPDATE_CONFIG_FOR_PROFILE_SUCCESS_RESPONSE.add(1, &[]);
Ok(service_api::ApplicationResponse::Json(
routing_types::ProfileDefaultRoutingConfig {
diff --git a/crates/router/src/core/split_payments.rs b/crates/router/src/core/split_payments.rs
index b3e83c506e..ee370a9f1e 100644
--- a/crates/router/src/core/split_payments.rs
+++ b/crates/router/src/core/split_payments.rs
@@ -94,7 +94,12 @@ async fn get_payment_method_amount_split(
field_name: "payment_method_data",
})?,
payment_method_type: request.payment_method_type,
- payment_method_subtype: request.payment_method_subtype,
+ payment_method_subtype: request
+ .payment_method_subtype
+ .get_required_value("payment_method_subtype")
+ .change_context(errors::ApiErrorResponse::MissingRequiredField {
+ field_name: "payment_method_subtype",
+ })?,
};
let combined_pm_data: Vec<_> = split_payment_method_data
@@ -576,7 +581,7 @@ pub async fn create_domain_model_for_split_payment(
payment_method_type,
payment_method_id: request.payment_method_id.clone(),
connector_payment_id: None,
- payment_method_subtype,
+ payment_method_subtype: Some(payment_method_subtype),
authentication_applied: None,
external_reference_id: None,
payment_method_billing_address,
diff --git a/crates/router/src/core/utils.rs b/crates/router/src/core/utils.rs
index 97c023793e..1e85e5ab5e 100644
--- a/crates/router/src/core/utils.rs
+++ b/crates/router/src/core/utils.rs
@@ -379,7 +379,7 @@ pub async fn construct_refund_router_data<'a, F>(
attempt_id: payment_attempt.id.get_string_repr().to_string().clone(),
status,
payment_method: payment_method_type,
- payment_method_type: Some(payment_attempt.payment_method_subtype),
+ payment_method_type: payment_attempt.payment_method_subtype,
connector_auth_type: auth_type,
description: None,
// Does refund need shipping/billing address ?
diff --git a/crates/router/src/core/utils/refunds_validator.rs b/crates/router/src/core/utils/refunds_validator.rs
index 29f97d1065..8dd4da3824 100644
--- a/crates/router/src/core/utils/refunds_validator.rs
+++ b/crates/router/src/core/utils/refunds_validator.rs
@@ -163,7 +163,7 @@ pub fn validate_for_valid_refunds(
(connector, payment_method_subtype),
(
api_models::enums::Connector::Braintree,
- diesel_models::enums::PaymentMethodType::Paypal,
+ Some(diesel_models::enums::PaymentMethodType::Paypal),
)
),
|| {
diff --git a/crates/router/src/db/events.rs b/crates/router/src/db/events.rs
index 3b78721db0..5a0edbd599 100644
--- a/crates/router/src/db/events.rs
+++ b/crates/router/src/db/events.rs
@@ -1406,6 +1406,7 @@ mod tests {
is_l2_l3_enabled: false,
network_tokenization_credentials: None,
payment_method_blocking: None,
+ default_fallback_routing: None,
});
let business_profile = state
diff --git a/crates/router/src/services/kafka/payment_attempt.rs b/crates/router/src/services/kafka/payment_attempt.rs
index 99a543c3e0..dfeb04dfe4 100644
--- a/crates/router/src/services/kafka/payment_attempt.rs
+++ b/crates/router/src/services/kafka/payment_attempt.rs
@@ -179,7 +179,7 @@ pub struct KafkaPaymentAttempt<'a> {
pub connector_metadata: Option<String>,
// TODO: These types should implement copy ideally
pub payment_experience: Option<&'a storage_enums::PaymentExperience>,
- pub payment_method_type: &'a storage_enums::PaymentMethodType,
+ pub payment_method_type: Option<&'a storage_enums::PaymentMethodType>,
pub payment_method_data: Option<String>,
pub error_reason: Option<&'a String>,
pub multiple_capture_count: Option<i16>,
@@ -212,7 +212,7 @@ pub struct KafkaPaymentAttempt<'a> {
pub processor_merchant_id: &'a id_type::MerchantId,
pub created_by: Option<&'a types::CreatedBy>,
pub payment_method_type_v2: storage_enums::PaymentMethod,
- pub payment_method_subtype: storage_enums::PaymentMethodType,
+ pub payment_method_subtype: Option<storage_enums::PaymentMethodType>,
pub routing_result: Option<serde_json::Value>,
pub authentication_applied: Option<common_enums::AuthenticationType>,
pub external_reference_id: Option<String>,
@@ -316,7 +316,7 @@ impl<'a> KafkaPaymentAttempt<'a> {
error_code: error.as_ref().map(|error_details| &error_details.code),
connector_metadata: connector_metadata.as_ref().map(|v| v.peek().to_string()),
payment_experience: payment_experience.as_ref(),
- payment_method_type: payment_method_subtype,
+ payment_method_type: payment_method_subtype.as_ref(),
payment_method_data: payment_method_data.as_ref().map(|v| v.peek().to_string()),
error_reason: error
.as_ref()
diff --git a/crates/router/src/services/kafka/payment_attempt_event.rs b/crates/router/src/services/kafka/payment_attempt_event.rs
index f3db7ffca4..7f24549502 100644
--- a/crates/router/src/services/kafka/payment_attempt_event.rs
+++ b/crates/router/src/services/kafka/payment_attempt_event.rs
@@ -181,7 +181,7 @@ pub struct KafkaPaymentAttemptEvent<'a> {
pub connector_metadata: Option<String>,
// TODO: These types should implement copy ideally
pub payment_experience: Option<&'a storage_enums::PaymentExperience>,
- pub payment_method_type: &'a storage_enums::PaymentMethodType,
+ pub payment_method_type: Option<&'a storage_enums::PaymentMethodType>,
pub payment_method_data: Option<String>,
pub error_reason: Option<&'a String>,
pub multiple_capture_count: Option<i16>,
@@ -214,7 +214,7 @@ pub struct KafkaPaymentAttemptEvent<'a> {
pub processor_merchant_id: &'a id_type::MerchantId,
pub created_by: Option<&'a types::CreatedBy>,
pub payment_method_type_v2: storage_enums::PaymentMethod,
- pub payment_method_subtype: storage_enums::PaymentMethodType,
+ pub payment_method_subtype: Option<storage_enums::PaymentMethodType>,
pub routing_result: Option<serde_json::Value>,
pub authentication_applied: Option<common_enums::AuthenticationType>,
pub external_reference_id: Option<String>,
@@ -318,7 +318,7 @@ impl<'a> KafkaPaymentAttemptEvent<'a> {
error_code: error.as_ref().map(|error_details| &error_details.code),
connector_metadata: connector_metadata.as_ref().map(|v| v.peek().to_string()),
payment_experience: payment_experience.as_ref(),
- payment_method_type: payment_method_subtype,
+ payment_method_type: payment_method_subtype.as_ref(),
payment_method_data: payment_method_data.as_ref().map(|v| v.peek().to_string()),
error_reason: error
.as_ref()
diff --git a/crates/router/src/types/api/admin.rs b/crates/router/src/types/api/admin.rs
index e062b50122..d1362d1059 100644
--- a/crates/router/src/types/api/admin.rs
+++ b/crates/router/src/types/api/admin.rs
@@ -541,5 +541,6 @@ pub async fn create_profile_from_merchant_account(
is_l2_l3_enabled: request.is_l2_l3_enabled.unwrap_or(false),
network_tokenization_credentials: None, // since credentials are at merchant level, they should not be in the profile, tracked in issue #15134
payment_method_blocking: None,
+ default_fallback_routing: None,
}))
}
diff --git a/crates/router/src/types/api/payment_methods.rs b/crates/router/src/types/api/payment_methods.rs
index 35f2bf7be1..4110caf37c 100644
--- a/crates/router/src/types/api/payment_methods.rs
+++ b/crates/router/src/types/api/payment_methods.rs
@@ -138,8 +138,19 @@ impl PaymentMethodCreateExt for PaymentMethodIntentConfirm {
}
#[cfg(feature = "v2")]
-impl PaymentMethodCreateExt for api_models::payment_methods::PaymentMethodSessionConfirmRequest {
- fn validate(&self) -> RouterResult<()> {
+pub(crate) trait PaymentMethodSessionExt {
+ fn validate(
+ &self,
+ payment_method_session: &hyperswitch_domain_models::payment_methods::PaymentMethodSession,
+ ) -> RouterResult<()>;
+}
+
+#[cfg(feature = "v2")]
+impl PaymentMethodSessionExt for api_models::payment_methods::PaymentMethodSessionConfirmRequest {
+ fn validate(
+ &self,
+ payment_method_session: &hyperswitch_domain_models::payment_methods::PaymentMethodSession,
+ ) -> RouterResult<()> {
utils::when(
self.payment_method_type != api_models::enums::PaymentMethod::Card
&& self.payment_method_subtype.is_none(),
@@ -150,6 +161,15 @@ impl PaymentMethodCreateExt for api_models::payment_methods::PaymentMethodSessio
},
)?;
+ utils::when(
+ payment_method_session.psp_tokenization.is_some() && self.customer_acceptance.is_none(),
+ || {
+ Err(report!(errors::ApiErrorResponse::MissingRequiredField {
+ field_name: "customer_acceptance"
+ }))
+ },
+ )?;
+
Ok(())
}
}
diff --git a/migrations/2026-03-22-000000_add_default_fallback_routing_to_business_profile/down.sql b/migrations/2026-03-22-000000_add_default_fallback_routing_to_business_profile/down.sql
new file mode 100644
index 0000000000..3f553950d4
--- /dev/null
+++ b/migrations/2026-03-22-000000_add_default_fallback_routing_to_business_profile/down.sql
@@ -0,0 +1 @@
+ALTER TABLE business_profile DROP COLUMN IF EXISTS default_fallback_routing;
diff --git a/migrations/2026-03-22-000000_add_default_fallback_routing_to_business_profile/up.sql b/migrations/2026-03-22-000000_add_default_fallback_routing_to_business_profile/up.sql
new file mode 100644
index 0000000000..2718d55ac7
--- /dev/null
+++ b/migrations/2026-03-22-000000_add_default_fallback_routing_to_business_profile/up.sql
@@ -0,0 +1 @@
+ALTER TABLE business_profile ADD COLUMN IF NOT EXISTS default_fallback_routing JSONB DEFAULT NULL;
diff --git a/v2_compatible_migrations/2024-08-28-081721_add_v2_columns/down.sql b/v2_compatible_migrations/2024-08-28-081721_add_v2_columns/down.sql
index e3c8777371..7786eba1a0 100644
--- a/v2_compatible_migrations/2024-08-28-081721_add_v2_columns/down.sql
+++ b/v2_compatible_migrations/2024-08-28-081721_add_v2_columns/down.sql
@@ -10,7 +10,6 @@ ALTER TABLE business_profile DROP COLUMN routing_algorithm_id,
DROP COLUMN order_fulfillment_time_origin,
DROP COLUMN frm_routing_algorithm_id,
DROP COLUMN payout_routing_algorithm_id,
- DROP COLUMN default_fallback_routing,
DROP COLUMN should_collect_cvv_during_payment,
DROP COLUMN three_ds_decision_manager_config;
diff --git a/v2_compatible_migrations/2024-08-28-081721_add_v2_columns/up.sql b/v2_compatible_migrations/2024-08-28-081721_add_v2_columns/up.sql
index 1dcedbff56..1aacd8ffc1 100644
--- a/v2_compatible_migrations/2024-08-28-081721_add_v2_columns/up.sql
+++ b/v2_compatible_migrations/2024-08-28-081721_add_v2_columns/up.sql
@@ -14,7 +14,6 @@ ADD COLUMN routing_algorithm_id VARCHAR(64) DEFAULT NULL,
ADD COLUMN order_fulfillment_time_origin "OrderFulfillmentTimeOrigin" DEFAULT NULL,
ADD COLUMN frm_routing_algorithm_id VARCHAR(64) DEFAULT NULL,
ADD COLUMN payout_routing_algorithm_id VARCHAR(64) DEFAULT NULL,
- ADD COLUMN default_fallback_routing JSONB DEFAULT NULL,
ADD COLUMN three_ds_decision_manager_config jsonb,
-- Intentionally not adding a default value here since we would have to
-- check if any merchants have enabled this from configs table,
diff --git a/v2_compatible_migrations/2026-03-24-000001_payment-method-subtype-optional-v2/down.sql b/v2_compatible_migrations/2026-03-24-000001_payment-method-subtype-optional-v2/down.sql
new file mode 100644
index 0000000000..138c6d93c8
--- /dev/null
+++ b/v2_compatible_migrations/2026-03-24-000001_payment-method-subtype-optional-v2/down.sql
@@ -0,0 +1,2 @@
+-- This file should undo anything in `up.sql`
+ALTER TABLE payment_attempt ALTER COLUMN payment_method_subtype SET NOT NULL;
diff --git a/v2_compatible_migrations/2026-03-24-000001_payment-method-subtype-optional-v2/up.sql b/v2_compatible_migrations/2026-03-24-000001_payment-method-subtype-optional-v2/up.sql
new file mode 100644
index 0000000000..f8483c1e9e
--- /dev/null
+++ b/v2_compatible_migrations/2026-03-24-000001_payment-method-subtype-optional-v2/up.sql
@@ -0,0 +1,2 @@
+-- Your SQL goes here
+ALTER TABLE payment_attempt ALTER COLUMN payment_method_subtype DROP NOT NULL;