Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 6 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions config/config.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions config/development.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
8 changes: 5 additions & 3 deletions config/docker_compose.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions crates/router/src/configs/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -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 {
Expand Down Expand Up @@ -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>,
}
Expand Down
13 changes: 6 additions & 7 deletions crates/router/src/core/payments/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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,
) {
Expand All @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
Expand Down Expand Up @@ -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)
})?;
Comment on lines -304 to -306
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this removed?


Ok((op, payment_method_data))
}

Expand Down