Skip to content

Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation

feat(router): disable temp locker call for connector-payment_method flow based on env (#2120)

Sai Harsha Vardhanfea5c4d8c186
diff --git a/config/config.example.toml b/config/config.example.toml
index 2d84d4f384..2a280f320f 100644
--- a/config/config.example.toml
+++ b/config/config.example.toml
@@ -311,6 +311,10 @@ stax = { long_lived_token = true, payment_method = "card,bank_debit" }
square = {long_lived_token = false, payment_method = "card"}
braintree = { long_lived_token = false, payment_method = "card" }
+[temp_locker_disable_config]
+trustpay = {payment_method = "card,bank_redirect,wallet"}
+stripe = {payment_method = "card,bank_redirect,pay_later,wallet,bank_debit"}
+
[dummy_connector]
payment_ttl = 172800 # Time to live for dummy connector payment in redis
payment_duration = 1000 # Fake delay duration for dummy connector payment
diff --git a/config/development.toml b/config/development.toml
index 44eba5f93d..9fc9dae8a2 100644
--- a/config/development.toml
+++ b/config/development.toml
@@ -373,6 +373,10 @@ square = {long_lived_token = false, payment_method = "card"}
braintree = { long_lived_token = false, payment_method = "card" }
payme = {long_lived_token = false, payment_method = "card"}
+[temp_locker_disable_config]
+trustpay = {payment_method = "card,bank_redirect,wallet"}
+stripe = {payment_method = "card,bank_redirect,pay_later,wallet,bank_debit"}
+
[connector_customer]
connector_list = "bluesnap,stax,stripe"
payout_connector_list = "wise"
diff --git a/config/docker_compose.toml b/config/docker_compose.toml
index adc41e1bb3..d2152cbb47 100644
--- a/config/docker_compose.toml
+++ b/config/docker_compose.toml
@@ -202,6 +202,10 @@ stax = { long_lived_token = true, payment_method = "card,bank_debit" }
square = {long_lived_token = false, payment_method = "card"}
braintree = { long_lived_token = false, payment_method = "card" }
+[temp_locker_disable_config]
+trustpay = {payment_method = "card,bank_redirect,wallet"}
+stripe = {payment_method = "card,bank_redirect,pay_later,wallet,bank_debit"}
+
[dummy_connector]
payment_ttl = 172800
payment_duration = 1000
diff --git a/crates/router/src/configs/settings.rs b/crates/router/src/configs/settings.rs
index 3739afc767..640f692d55 100644
--- a/crates/router/src/configs/settings.rs
+++ b/crates/router/src/configs/settings.rs
@@ -97,6 +97,7 @@ pub struct Settings {
pub applepay_decrypt_keys: ApplePayDecryptConifg,
pub multiple_api_version_supported_connectors: MultipleApiVersionSupportedConnectors,
pub applepay_merchant_configs: ApplepayMerchantConfigs,
+ pub temp_locker_disable_config: TempLockerDisableConfig,
}
#[derive(Debug, Deserialize, Clone, Default)]
@@ -118,6 +119,10 @@ pub struct MultipleApiVersionSupportedConnectors {
#[serde(transparent)]
pub struct TokenizationConfig(pub HashMap<String, PaymentMethodTokenFilter>);
+#[derive(Debug, Deserialize, Clone, Default)]
+#[serde(transparent)]
+pub struct TempLockerDisableConfig(pub HashMap<String, TempLockerDisablePaymentMethodFilter>);
+
#[derive(Debug, Deserialize, Clone, Default)]
pub struct ConnectorCustomer {
#[serde(deserialize_with = "connector_deser")]
@@ -207,6 +212,12 @@ pub struct PaymentMethodTokenFilter {
pub long_lived_token: bool,
}
+#[derive(Debug, Deserialize, Clone, Default)]
+pub struct TempLockerDisablePaymentMethodFilter {
+ #[serde(deserialize_with = "pm_deser")]
+ pub payment_method: HashSet<diesel_models::enums::PaymentMethod>,
+}
+
#[derive(Debug, Deserialize, Clone, Default)]
#[serde(
deny_unknown_fields,
diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rs
index 892f8fe239..6efba6aa81 100644
--- a/crates/router/src/core/payments/helpers.rs
+++ b/crates/router/src/core/payments/helpers.rs
@@ -35,7 +35,7 @@ use super::{
#[cfg(feature = "kms")]
use crate::connector;
use crate::{
- configs::settings::{ConnectorRequestReferenceIdConfig, Server},
+ configs::settings::{ConnectorRequestReferenceIdConfig, Server, TempLockerDisableConfig},
consts::{self, BASE64_ENGINE},
core::{
errors::{self, CustomResult, RouterResult, StorageErrorExt},
@@ -1294,17 +1294,22 @@ pub async fn make_pm_data<'a, F: Clone, R>(
})
}
(pm_opt @ Some(pm @ api::PaymentMethodData::Card(_)), _) => {
- let parent_payment_method_token = store_in_vault_and_generate_ppmt(
- state,
- pm,
- &payment_data.payment_intent,
- &payment_data.payment_attempt,
+ if should_store_payment_method_data_in_vault(
+ &state.conf.temp_locker_disable_config,
+ payment_data.payment_attempt.connector.clone(),
enums::PaymentMethod::Card,
- )
- .await?;
-
- payment_data.token = Some(parent_payment_method_token);
+ ) {
+ let parent_payment_method_token = store_in_vault_and_generate_ppmt(
+ state,
+ pm,
+ &payment_data.payment_intent,
+ &payment_data.payment_attempt,
+ enums::PaymentMethod::Card,
+ )
+ .await?;
+ payment_data.token = Some(parent_payment_method_token);
+ }
Ok(pm_opt.to_owned())
}
(pm @ Some(api::PaymentMethodData::PayLater(_)), _) => Ok(pm.to_owned()),
@@ -1316,42 +1321,60 @@ pub async fn make_pm_data<'a, F: Clone, R>(
(pm @ Some(api::PaymentMethodData::CardRedirect(_)), _) => Ok(pm.to_owned()),
(pm @ Some(api::PaymentMethodData::GiftCard(_)), _) => Ok(pm.to_owned()),
(pm_opt @ Some(pm @ api::PaymentMethodData::BankTransfer(_)), _) => {
- let parent_payment_method_token = store_in_vault_and_generate_ppmt(
- state,
- pm,
- &payment_data.payment_intent,
- &payment_data.payment_attempt,
+ if should_store_payment_method_data_in_vault(
+ &state.conf.temp_locker_disable_config,
+ payment_data.payment_attempt.connector.clone(),
enums::PaymentMethod::BankTransfer,
- )
- .await?;
+ ) {
+ let parent_payment_method_token = store_in_vault_and_generate_ppmt(
+ state,
+ pm,
+ &payment_data.payment_intent,
+ &payment_data.payment_attempt,
+ enums::PaymentMethod::BankTransfer,
+ )
+ .await?;
- payment_data.token = Some(parent_payment_method_token);
+ payment_data.token = Some(parent_payment_method_token);
+ }
Ok(pm_opt.to_owned())
}
(pm_opt @ Some(pm @ api::PaymentMethodData::Wallet(_)), _) => {
- let parent_payment_method_token = store_in_vault_and_generate_ppmt(
- state,
- pm,
- &payment_data.payment_intent,
- &payment_data.payment_attempt,
+ if should_store_payment_method_data_in_vault(
+ &state.conf.temp_locker_disable_config,
+ payment_data.payment_attempt.connector.clone(),
enums::PaymentMethod::Wallet,
- )
- .await?;
+ ) {
+ let parent_payment_method_token = store_in_vault_and_generate_ppmt(
+ state,
+ pm,
+ &payment_data.payment_intent,
+ &payment_data.payment_attempt,
+ enums::PaymentMethod::Wallet,
+ )
+ .await?;
- payment_data.token = Some(parent_payment_method_token);
+ payment_data.token = Some(parent_payment_method_token);
+ }
Ok(pm_opt.to_owned())
}
(pm_opt @ Some(pm @ api::PaymentMethodData::BankRedirect(_)), _) => {
- let parent_payment_method_token = store_in_vault_and_generate_ppmt(
- state,
- pm,
- &payment_data.payment_intent,
- &payment_data.payment_attempt,
+ if should_store_payment_method_data_in_vault(
+ &state.conf.temp_locker_disable_config,
+ payment_data.payment_attempt.connector.clone(),
enums::PaymentMethod::BankRedirect,
- )
- .await?;
- payment_data.token = Some(parent_payment_method_token);
+ ) {
+ let parent_payment_method_token = store_in_vault_and_generate_ppmt(
+ state,
+ pm,
+ &payment_data.payment_intent,
+ &payment_data.payment_attempt,
+ enums::PaymentMethod::BankRedirect,
+ )
+ .await?;
+ payment_data.token = Some(parent_payment_method_token);
+ }
Ok(pm_opt.to_owned())
}
_ => Ok(None),
@@ -1390,6 +1413,23 @@ pub async fn store_in_vault_and_generate_ppmt(
Ok(parent_payment_method_token)
}
+pub fn should_store_payment_method_data_in_vault(
+ temp_locker_disable_config: &TempLockerDisableConfig,
+ option_connector: Option<String>,
+ payment_method: enums::PaymentMethod,
+) -> bool {
+ option_connector
+ .map(|connector| {
+ temp_locker_disable_config
+ .0
+ .get(&connector)
+ //should be true only if payment_method is not in the disable payment_method list for connector
+ .map(|config| !config.payment_method.contains(&payment_method))
+ .unwrap_or(true)
+ })
+ .unwrap_or(true)
+}
+
#[instrument(skip_all)]
pub(crate) fn validate_capture_method(
capture_method: storage_enums::CaptureMethod,
diff --git a/crates/router/src/core/payments/operations/payment_complete_authorize.rs b/crates/router/src/core/payments/operations/payment_complete_authorize.rs
index c06c8e4e77..18315969d2 100644
--- a/crates/router/src/core/payments/operations/payment_complete_authorize.rs
+++ b/crates/router/src/core/payments/operations/payment_complete_authorize.rs
@@ -108,13 +108,24 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Co
let token = token.or_else(|| payment_attempt.payment_token.clone());
- helpers::validate_pm_or_token_given(
- &request.payment_method,
- &request.payment_method_data,
- &request.payment_method_type,
- &mandate_type,
- &token,
- )?;
+ if let Some(payment_method) = payment_method {
+ let should_validate_pm_or_token_given =
+ //this validation should happen if data was stored in the vault
+ helpers::should_store_payment_method_data_in_vault(
+ &state.conf.temp_locker_disable_config,
+ payment_attempt.connector.clone(),
+ payment_method,
+ );
+ if should_validate_pm_or_token_given {
+ helpers::validate_pm_or_token_given(
+ &request.payment_method,
+ &request.payment_method_data,
+ &request.payment_method_type,
+ &mandate_type,
+ &token,
+ )?;
+ }
+ }
payment_attempt.payment_method = payment_method.or(payment_attempt.payment_method);
payment_attempt.browser_info = browser_info;