feat(router): change temp locker config as enable only (#2522)

This commit is contained in:
Sai Harsha Vardhan
2023-10-10 21:05:12 +05:30
committed by GitHub
parent a808c02501
commit 7acf101014
6 changed files with 25 additions and 25 deletions

View File

@ -321,9 +321,11 @@ square = {long_lived_token = false, payment_method = "card"}
braintree = { long_lived_token = false, payment_method = "card" }
gocardless = {long_lived_token = true, payment_method = "bank_debit"}
[temp_locker_disable_config]
trustpay = {payment_method = "card,bank_redirect,wallet"}
stripe = {payment_method = "card,bank_redirect,pay_later,wallet,bank_debit"}
[temp_locker_enable_config]
stripe = {payment_method = "bank_transfer"}
nuvei = {payment_method = "card"}
shift4 = {payment_method = "card"}
bluesnap = {payment_method = "card"}
[dummy_connector]
enabled = true # Whether dummy connector is enabled or not

View File

@ -377,9 +377,11 @@ braintree = { long_lived_token = false, payment_method = "card" }
payme = {long_lived_token = false, payment_method = "card"}
gocardless = {long_lived_token = true, payment_method = "bank_debit"}
[temp_locker_disable_config]
trustpay = {payment_method = "card,bank_redirect,wallet"}
stripe = {payment_method = "card,bank_redirect,pay_later,wallet,bank_debit"}
[temp_locker_enable_config]
stripe = {payment_method = "bank_transfer"}
nuvei = {payment_method = "card"}
shift4 = {payment_method = "card"}
bluesnap = {payment_method = "card"}
[connector_customer]
connector_list = "gocardless,stax,stripe"

View File

@ -208,9 +208,11 @@ square = {long_lived_token = false, payment_method = "card"}
braintree = { long_lived_token = false, payment_method = "card" }
gocardless = {long_lived_token = true, payment_method = "bank_debit"}
[temp_locker_disable_config]
trustpay = {payment_method = "card,bank_redirect,wallet"}
stripe = {payment_method = "card,bank_redirect,pay_later,wallet,bank_debit"}
[temp_locker_enable_config]
stripe = {payment_method = "bank_transfer"}
nuvei = {payment_method = "card"}
shift4 = {payment_method = "card"}
bluesnap = {payment_method = "card"}
[dummy_connector]
enabled = true

View File

@ -99,7 +99,7 @@ pub struct Settings {
pub multiple_api_version_supported_connectors: MultipleApiVersionSupportedConnectors,
pub applepay_merchant_configs: ApplepayMerchantConfigs,
pub lock_settings: LockSettings,
pub temp_locker_disable_config: TempLockerDisableConfig,
pub temp_locker_enable_config: TempLockerEnableConfig,
}
#[derive(Debug, Deserialize, Clone, Default)]
@ -123,7 +123,7 @@ pub struct TokenizationConfig(pub HashMap<String, PaymentMethodTokenFilter>);
#[derive(Debug, Deserialize, Clone, Default)]
#[serde(transparent)]
pub struct TempLockerDisableConfig(pub HashMap<String, TempLockerDisablePaymentMethodFilter>);
pub struct TempLockerEnableConfig(pub HashMap<String, TempLockerEnablePaymentMethodFilter>);
#[derive(Debug, Deserialize, Clone, Default)]
pub struct ConnectorCustomer {
@ -216,7 +216,7 @@ pub struct PaymentMethodTokenFilter {
}
#[derive(Debug, Deserialize, Clone, Default)]
pub struct TempLockerDisablePaymentMethodFilter {
pub struct TempLockerEnablePaymentMethodFilter {
#[serde(deserialize_with = "pm_deser")]
pub payment_method: HashSet<diesel_models::enums::PaymentMethod>,
}

View File

@ -31,7 +31,7 @@ use super::{
CustomerDetails, PaymentData,
};
use crate::{
configs::settings::{ConnectorRequestReferenceIdConfig, Server, TempLockerDisableConfig},
configs::settings::{ConnectorRequestReferenceIdConfig, Server, TempLockerEnableConfig},
connector,
consts::{self, BASE64_ENGINE},
core::{
@ -1480,7 +1480,7 @@ pub async fn store_payment_method_data_in_vault(
payment_method_data: &api::PaymentMethodData,
) -> RouterResult<Option<String>> {
if should_store_payment_method_data_in_vault(
&state.conf.temp_locker_disable_config,
&state.conf.temp_locker_enable_config,
payment_attempt.connector.clone(),
payment_method,
) {
@ -1499,18 +1499,17 @@ pub async fn store_payment_method_data_in_vault(
Ok(None)
}
pub fn should_store_payment_method_data_in_vault(
temp_locker_disable_config: &TempLockerDisableConfig,
temp_locker_enable_config: &TempLockerEnableConfig,
option_connector: Option<String>,
payment_method: enums::PaymentMethod,
) -> bool {
option_connector
.map(|connector| {
temp_locker_disable_config
temp_locker_enable_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)
.map(|config| config.payment_method.contains(&payment_method))
.unwrap_or(false)
})
.unwrap_or(true)
}

View File

@ -115,7 +115,7 @@ impl<F: Send + Clone, Ctx: PaymentMethodRetrieve>
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,
&state.conf.temp_locker_enable_config,
payment_attempt.connector.clone(),
payment_method,
);
@ -300,11 +300,6 @@ impl<F: Clone + Send, Ctx: PaymentMethodRetrieve> Domain<F, api::PaymentsRequest
)> {
let (op, payment_method_data) =
helpers::make_pm_data(Box::new(self), state, payment_data).await?;
utils::when(payment_method_data.is_none(), || {
Err(errors::ApiErrorResponse::PaymentMethodNotFound)
})?;
Ok((op, payment_method_data))
}