Skip to content

Commit dfc6be4

Browse files
feat(pm_list): add pm list support for bank_debits (#1120)
1 parent a2527b5 commit dfc6be4

File tree

2 files changed

+78
-6
lines changed

2 files changed

+78
-6
lines changed

crates/api_models/src/payment_methods.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,11 @@ pub struct CardNetworkTypes {
183183
pub eligible_connectors: Vec<String>,
184184
}
185185

186+
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, ToSchema, PartialEq, Eq)]
187+
pub struct BankDebitTypes {
188+
pub eligible_connectors: Vec<String>,
189+
}
190+
186191
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, ToSchema, PartialEq, Eq)]
187192
pub struct ResponsePaymentMethodTypes {
188193
/// The payment method type enabled
@@ -197,6 +202,9 @@ pub struct ResponsePaymentMethodTypes {
197202

198203
/// The list of banks enabled, if applicable for a payment method type
199204
pub bank_names: Option<Vec<BankCodeResponse>>,
205+
206+
/// The Bank debit payment method information, if applicable for a payment method type.
207+
pub bank_debits: Option<BankDebitTypes>,
200208
}
201209

202210
#[derive(Debug, Clone, serde::Deserialize, serde::Serialize, ToSchema)]

crates/router/src/core/payment_methods/cards.rs

Lines changed: 70 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -837,10 +837,13 @@ pub async fn list_payment_methods(
837837
.await
838838
.to_not_found_response(errors::ApiErrorResponse::MerchantAccountNotFound)?;
839839

840-
logger::debug!(mca_before_filtering=?all_mcas);
840+
// filter out connectors based on the business country
841+
let filtered_mcas = filter_mca_based_on_business_details(all_mcas, payment_intent.as_ref());
842+
843+
logger::debug!(mca_before_filtering=?filtered_mcas);
841844

842845
let mut response: Vec<ResponsePaymentMethodIntermediate> = vec![];
843-
for mca in all_mcas {
846+
for mca in filtered_mcas {
844847
let payment_methods = match mca.payment_methods_enabled {
845848
Some(pm) => pm,
846849
None => continue,
@@ -874,6 +877,9 @@ pub async fn list_payment_methods(
874877
let mut banks_consolidated_hm: HashMap<api_enums::PaymentMethodType, Vec<String>> =
875878
HashMap::new();
876879

880+
let mut bank_debits_consolidated_hm =
881+
HashMap::<api_enums::PaymentMethodType, Vec<String>>::new();
882+
877883
for element in response.clone() {
878884
let payment_method = element.payment_method;
879885
let payment_method_type = element.payment_method_type;
@@ -964,6 +970,17 @@ pub async fn list_payment_methods(
964970
banks_consolidated_hm.insert(element.payment_method_type, vec![connector]);
965971
}
966972
}
973+
974+
if element.payment_method == api_enums::PaymentMethod::BankDebit {
975+
let connector = element.connector.clone();
976+
if let Some(vector_of_connectors) =
977+
bank_debits_consolidated_hm.get_mut(&element.payment_method_type)
978+
{
979+
vector_of_connectors.push(connector);
980+
} else {
981+
bank_debits_consolidated_hm.insert(element.payment_method_type, vec![connector]);
982+
}
983+
}
967984
}
968985

969986
let mut payment_method_responses: Vec<ResponsePaymentMethodsEnabled> = vec![];
@@ -983,6 +1000,7 @@ pub async fn list_payment_methods(
9831000
payment_experience: Some(payment_experience_types),
9841001
card_networks: None,
9851002
bank_names: None,
1003+
bank_debits: None,
9861004
})
9871005
}
9881006

@@ -1008,6 +1026,7 @@ pub async fn list_payment_methods(
10081026
card_networks: Some(card_network_types),
10091027
payment_experience: None,
10101028
bank_names: None,
1029+
bank_debits: None,
10111030
})
10121031
}
10131032

@@ -1017,26 +1036,52 @@ pub async fn list_payment_methods(
10171036
})
10181037
}
10191038

1020-
let mut bank_payment_method_types = vec![];
1039+
let mut bank_redirect_payment_method_types = vec![];
10211040

10221041
for key in banks_consolidated_hm.iter() {
10231042
let payment_method_type = *key.0;
10241043
let connectors = key.1.clone();
10251044
let bank_names = get_banks(state, payment_method_type, connectors)?;
1026-
bank_payment_method_types.push({
1045+
bank_redirect_payment_method_types.push({
10271046
ResponsePaymentMethodTypes {
10281047
payment_method_type,
10291048
bank_names: Some(bank_names),
10301049
payment_experience: None,
10311050
card_networks: None,
1051+
bank_debits: None,
10321052
}
10331053
})
10341054
}
10351055

1036-
if !bank_payment_method_types.is_empty() {
1056+
if !bank_redirect_payment_method_types.is_empty() {
10371057
payment_method_responses.push(ResponsePaymentMethodsEnabled {
10381058
payment_method: api_enums::PaymentMethod::BankRedirect,
1039-
payment_method_types: bank_payment_method_types,
1059+
payment_method_types: bank_redirect_payment_method_types,
1060+
});
1061+
}
1062+
1063+
let mut bank_debit_payment_method_types = vec![];
1064+
1065+
for key in bank_debits_consolidated_hm.iter() {
1066+
let payment_method_type = *key.0;
1067+
let connectors = key.1.clone();
1068+
bank_debit_payment_method_types.push({
1069+
ResponsePaymentMethodTypes {
1070+
payment_method_type,
1071+
bank_names: None,
1072+
payment_experience: None,
1073+
card_networks: None,
1074+
bank_debits: Some(api_models::payment_methods::BankDebitTypes {
1075+
eligible_connectors: connectors,
1076+
}),
1077+
}
1078+
})
1079+
}
1080+
1081+
if !bank_debit_payment_method_types.is_empty() {
1082+
payment_method_responses.push(ResponsePaymentMethodsEnabled {
1083+
payment_method: api_enums::PaymentMethod::BankDebit,
1084+
payment_method_types: bank_debit_payment_method_types,
10401085
});
10411086
}
10421087

@@ -1169,6 +1214,25 @@ async fn filter_payment_methods(
11691214
Ok(())
11701215
}
11711216

1217+
fn filter_mca_based_on_business_details(
1218+
merchant_connector_accounts: Vec<
1219+
storage_models::merchant_connector_account::MerchantConnectorAccount,
1220+
>,
1221+
payment_intent: Option<&storage_models::payment_intent::PaymentIntent>,
1222+
) -> Vec<storage_models::merchant_connector_account::MerchantConnectorAccount> {
1223+
if let Some(payment_intent) = payment_intent {
1224+
merchant_connector_accounts
1225+
.into_iter()
1226+
.filter(|mca| {
1227+
mca.business_country == payment_intent.business_country
1228+
&& mca.business_label == payment_intent.business_label
1229+
})
1230+
.collect::<Vec<_>>()
1231+
} else {
1232+
merchant_connector_accounts
1233+
}
1234+
}
1235+
11721236
fn filter_pm_based_on_config<'a>(
11731237
config: &'a crate::configs::settings::ConnectorFilters,
11741238
connector: &'a str,

0 commit comments

Comments
 (0)