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(router): prevent creation of saved klarna and affirm payment methods (#10813)

AkshayaFoiger0d96e0beda96
diff --git a/config/deployments/integration_test.toml b/config/deployments/integration_test.toml
index 6e211b95ce..f35343aad6 100644
--- a/config/deployments/integration_test.toml
+++ b/config/deployments/integration_test.toml
@@ -215,6 +215,9 @@ payout_connector_list = "nomupay,stripe,wise"
[delayed_session_response]
connectors_with_delayed_session_response = "trustpay,payme" # List of connectors which have delayed session response
+[save_payment_method_on_session.unsupported_payment_methods]
+pay_later = ["klarna", "affirm"]
+
[zero_mandates.supported_payment_methods]
bank_debit.ach = { connector_list = "gocardless,adyen,payload" }
bank_debit.becs = { connector_list = "gocardless,adyen" }
diff --git a/config/deployments/production.toml b/config/deployments/production.toml
index a350c65f33..ef7c9d405e 100644
--- a/config/deployments/production.toml
+++ b/config/deployments/production.toml
@@ -184,6 +184,9 @@ netcetera.base_url = "https://{{merchant_endpoint_prefix}}.3ds-server.prod.netce
[delayed_session_response]
connectors_with_delayed_session_response = "trustpay,payme" # List of connectors which have delayed session response
+[save_payment_method_on_session.unsupported_payment_methods]
+pay_later = ["klarna", "affirm"]
+
[dummy_connector]
enabled = false # Whether dummy connector is enabled or not
assets_base_url = "https://app.hyperswitch.io/assets/TestProcessor/" # Base url for dummy connector assets
diff --git a/config/deployments/sandbox.toml b/config/deployments/sandbox.toml
index ca3a60ff03..ca84183e16 100644
--- a/config/deployments/sandbox.toml
+++ b/config/deployments/sandbox.toml
@@ -184,6 +184,9 @@ netcetera.base_url = "https://{{merchant_endpoint_prefix}}.3ds-server.prev.netce
[delayed_session_response]
connectors_with_delayed_session_response = "trustpay,payme" # List of connectors which have delayed session response
+[save_payment_method_on_session.unsupported_payment_methods]
+pay_later = ["klarna", "affirm"]
+
[dummy_connector]
enabled = true # Whether dummy connector is enabled or not
assets_base_url = "https://app.hyperswitch.io/assets/TestProcessor/" # Base url for dummy connector assets
diff --git a/config/development.toml b/config/development.toml
index 77615d91f0..e39401c9a3 100644
--- a/config/development.toml
+++ b/config/development.toml
@@ -1112,6 +1112,9 @@ discord_invite_url = "https://discord.gg/wJZ7DVW8mm"
[delayed_session_response]
connectors_with_delayed_session_response = "trustpay,payme"
+[save_payment_method_on_session.unsupported_payment_methods]
+pay_later = ["klarna", "affirm"]
+
[webhook_source_verification_call]
connectors_with_webhook_source_verification_call = "paypal"
diff --git a/config/docker_compose.toml b/config/docker_compose.toml
index c4c6f9ecdd..ddbce5bb32 100644
--- a/config/docker_compose.toml
+++ b/config/docker_compose.toml
@@ -398,6 +398,9 @@ cards = [
[delayed_session_response]
connectors_with_delayed_session_response = "trustpay,payme"
+[save_payment_method_on_session.unsupported_payment_methods]
+pay_later = ["klarna", "affirm"]
+
[webhook_source_verification_call]
connectors_with_webhook_source_verification_call = "paypal"
diff --git a/crates/common_enums/src/enums.rs b/crates/common_enums/src/enums.rs
index aa4a869d38..a702feb777 100644
--- a/crates/common_enums/src/enums.rs
+++ b/crates/common_enums/src/enums.rs
@@ -2071,6 +2071,13 @@ impl FutureUsage {
Self::OnSession => false,
}
}
+ /// Indicates whether to save the payment method for future use when a customer is present.
+ pub fn is_on_session(self) -> bool {
+ match self {
+ Self::OffSession => false,
+ Self::OnSession => true,
+ }
+ }
}
#[derive(
diff --git a/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs b/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs
index ffde86e813..b8789320ac 100644
--- a/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs
+++ b/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs
@@ -1433,6 +1433,22 @@ impl PaymentAttempt {
self.payment_method_data.clone()
}
}
+
+ // Check if the payment method type does not support saving during on-session payments
+ pub fn is_save_payment_method_not_supported_for_on_session(
+ &self,
+ unsupported_payment_methods: &std::collections::HashMap<
+ common_enums::PaymentMethod,
+ std::collections::HashSet<common_enums::PaymentMethodType>,
+ >,
+ ) -> bool {
+ self.payment_method_type.is_some_and(|pm_type| {
+ self.payment_method
+ .as_ref()
+ .and_then(|method| unsupported_payment_methods.get(method))
+ .is_some_and(|unsupported_set| unsupported_set.contains(&pm_type))
+ })
+ }
}
#[derive(Clone, Debug, Eq, PartialEq)]
diff --git a/crates/router/src/configs/secrets_transformers.rs b/crates/router/src/configs/secrets_transformers.rs
index b1365eabdb..18605b94fc 100644
--- a/crates/router/src/configs/secrets_transformers.rs
+++ b/crates/router/src/configs/secrets_transformers.rs
@@ -638,5 +638,6 @@ pub(crate) async fn fetch_raw_secrets(
internal_services: conf.internal_services,
superposition,
comparison_service: conf.comparison_service,
+ save_payment_method_on_session: conf.save_payment_method_on_session,
}
}
diff --git a/crates/router/src/configs/settings.rs b/crates/router/src/configs/settings.rs
index c9d960fe6b..8129d70368 100644
--- a/crates/router/src/configs/settings.rs
+++ b/crates/router/src/configs/settings.rs
@@ -182,6 +182,13 @@ pub struct Settings<S: SecretState> {
pub trace_header: TraceHeaderConfig,
pub internal_services: InternalServicesConfig,
pub comparison_service: Option<ComparisonServiceConfig>,
+ pub save_payment_method_on_session: OnSessionConfig,
+}
+
+#[derive(Debug, Deserialize, Clone, Default)]
+pub struct OnSessionConfig {
+ pub unsupported_payment_methods:
+ HashMap<enums::PaymentMethod, HashSet<enums::PaymentMethodType>>,
}
#[derive(Debug, Deserialize, Clone, Default)]
diff --git a/crates/router/src/core/payments/operations/payment_response.rs b/crates/router/src/core/payments/operations/payment_response.rs
index b25b49ad0a..e5b6e2c03e 100644
--- a/crates/router/src/core/payments/operations/payment_response.rs
+++ b/crates/router/src/core/payments/operations/payment_response.rs
@@ -222,6 +222,26 @@ impl<F: Send + Clone> PostUpdateTracker<F, PaymentData<F>, types::PaymentsAuthor
Some(enums::FutureUsage::OffSession)
);
let storage_scheme = platform.get_processor().get_account().storage_scheme;
+
+ // Skip payment method creation when on-session saving is not supported for the payment method
+ should_avoid_saving = if resp
+ .request
+ .setup_future_usage
+ .map(|usage| usage.is_on_session())
+ .unwrap_or(false)
+ && payment_data
+ .payment_attempt
+ .is_save_payment_method_not_supported_for_on_session(
+ &state
+ .conf
+ .save_payment_method_on_session
+ .unsupported_payment_methods,
+ ) {
+ true
+ } else {
+ should_avoid_saving
+ };
+
if is_legacy_mandate {
// Mandate is created on the application side and at the connector.
let tokenization::SavePaymentMethodDataResponse {