feat(pm_list): add available capture methods filter (#999)

Co-authored-by: Arun Raj M <jarnura47@gmail.com>
This commit is contained in:
Prajjwal Kumar
2023-05-03 16:10:05 +05:30
committed by GitHub
parent 03a96432a9
commit 36cc13d44b
3 changed files with 61 additions and 5 deletions

View File

@ -177,9 +177,33 @@ ideal = { country = "NL", currency = "EUR" }
[pm_filters.braintree]
paypal = { currency = "AUD,BRL,CAD,CNY,CZK,DKK,EUR,HKD,HUF,ILS,JPY,MYR,MXN,TWD,NZD,NOK,PHP,PLN,GBP,RUB,SGD,SEK,CHF,THB,USD" }
credit = { not_available_flows = {capture_method="manual"} }
debit = { not_available_flows = {capture_method="manual"} }
[pm_filters.klarna]
klarna = { country = "AU,AT,BE,CA,CZ,DK,FI,FR,DE,GR,IE,IT,NL,NZ,NO,PL,PT,ES,SE,CH,GB,US", currency = "AUD,EUR,EUR,CAD,CZK,DKK,EUR,EUR,EUR,EUR,EUR,EUR,EUR,NZD,NOK,PLN,EUR,EUR,SEK,CHF,GBP,USD" }
credit = { not_available_flows = {capture_method="manual"} }
debit = { not_available_flows = {capture_method="manual"} }
[pm_filters.zen]
credit = { not_available_flows = {capture_method="manual"} }
debit = { not_available_flows = {capture_method="manual"} }
[pm_filters.aci]
credit = { not_available_flows = {capture_method="manual"} }
debit = { not_available_flows = {capture_method="manual"} }
[pm_filters.mollie]
credit = { not_available_flows = {capture_method="manual"} }
debit = { not_available_flows = {capture_method="manual"} }
[pm_filters.multisafepay]
credit = { not_available_flows = {capture_method="manual"} }
debit = { not_available_flows = {capture_method="manual"} }
[pm_filters.trustpay]
credit = { not_available_flows = {capture_method="manual"} }
debit = { not_available_flows = {capture_method="manual"} }
[pm_filters.authorizedotnet]
google_pay = { currency = "CHF,DKK,EUR,GBP,NOK,PLN,SEK,USD,AUD,NZD,CAD" }

View File

@ -4,6 +4,7 @@ use std::{
str::FromStr,
};
use api_models::enums;
use common_utils::ext_traits::ConfigExt;
use config::{Environment, File};
#[cfg(feature = "kms")]
@ -133,7 +134,7 @@ pub struct ConnectorFilters(pub HashMap<String, PaymentMethodFilters>);
#[derive(Debug, Deserialize, Clone, Default)]
#[serde(transparent)]
pub struct PaymentMethodFilters(pub HashMap<PaymentMethodFilterKey, CurrencyCountryFilter>);
pub struct PaymentMethodFilters(pub HashMap<PaymentMethodFilterKey, CurrencyCountryFlowFilter>);
#[derive(Debug, Deserialize, Clone, PartialEq, Eq, Hash)]
#[serde(untagged)]
@ -144,11 +145,17 @@ pub enum PaymentMethodFilterKey {
#[derive(Debug, Deserialize, Clone, Default)]
#[serde(default)]
pub struct CurrencyCountryFilter {
pub struct CurrencyCountryFlowFilter {
#[serde(deserialize_with = "currency_set_deser")]
pub currency: Option<HashSet<api_models::enums::Currency>>,
#[serde(deserialize_with = "string_set_deser")]
pub country: Option<HashSet<api_models::enums::CountryAlpha2>>,
pub not_available_flows: Option<NotAvailableFlows>,
}
#[derive(Debug, Deserialize, Copy, Clone, Default)]
#[serde(default)]
pub struct NotAvailableFlows {
pub capture_method: Option<enums::CaptureMethod>,
}
fn string_set_deser<'a, D>(

View File

@ -17,7 +17,7 @@ use common_utils::{
};
use error_stack::{report, IntoReport, ResultExt};
use router_env::{instrument, tracing};
use storage_models::payment_method;
use storage_models::{enums as storage_enums, payment_method};
#[cfg(feature = "basilisk")]
use crate::scheduler::metrics as scheduler_metrics;
@ -1127,6 +1127,7 @@ async fn filter_payment_methods(
config,
&connector,
&payment_method_object.payment_method_type,
payment_attempt,
&mut payment_method_object.card_networks,
&address.and_then(|inner| inner.country),
payment_attempt
@ -1161,6 +1162,7 @@ fn filter_pm_based_on_config<'a>(
config: &'a crate::configs::settings::ConnectorFilters,
connector: &'a str,
payment_method_type: &'a api_enums::PaymentMethodType,
payment_attempt: Option<&storage::PaymentAttempt>,
card_network: &mut Option<Vec<api_enums::CardNetwork>>,
country: &Option<api_enums::CountryAlpha2>,
currency: Option<api_enums::Currency>,
@ -1171,7 +1173,14 @@ fn filter_pm_based_on_config<'a>(
.and_then(|inner| match payment_method_type {
api_enums::PaymentMethodType::Credit | api_enums::PaymentMethodType::Debit => {
card_network_filter(country, currency, card_network, inner);
None
payment_attempt
.and_then(|inner| inner.capture_method)
.and_then(|capture_method| {
(capture_method == storage_enums::CaptureMethod::Manual).then(|| {
filter_pm_based_on_capture_method_used(inner, payment_method_type)
})
})
}
payment_method_type => inner
.0
@ -1183,6 +1192,22 @@ fn filter_pm_based_on_config<'a>(
.unwrap_or(true)
}
///Filters the payment method list on basis of Capture methods, checks whether the connector issues Manual payments using cards or not if not it won't be visible in payment methods list
fn filter_pm_based_on_capture_method_used(
payment_method_filters: &settings::PaymentMethodFilters,
payment_method_type: &api_enums::PaymentMethodType,
) -> bool {
payment_method_filters
.0
.get(&settings::PaymentMethodFilterKey::PaymentMethodType(
*payment_method_type,
))
.and_then(|v| v.not_available_flows)
.and_then(|v| v.capture_method)
.map(|v| !matches!(v, api_enums::CaptureMethod::Manual))
.unwrap_or(true)
}
fn card_network_filter(
country: &Option<api_enums::CountryAlpha2>,
currency: Option<api_enums::Currency>,
@ -1207,7 +1232,7 @@ fn card_network_filter(
}
fn global_country_currency_filter(
item: &settings::CurrencyCountryFilter,
item: &settings::CurrencyCountryFlowFilter,
country: &Option<api_enums::CountryAlpha2>,
currency: Option<api_enums::Currency>,
) -> bool {