mirror of
				https://github.com/juspay/hyperswitch.git
				synced 2025-11-01 02:57:02 +08:00 
			
		
		
		
	feat(pm_list): add pm list support for bank_debits (#1120)
This commit is contained in:
		| @ -837,10 +837,13 @@ pub async fn list_payment_methods( | ||||
|         .await | ||||
|         .to_not_found_response(errors::ApiErrorResponse::MerchantAccountNotFound)?; | ||||
|  | ||||
|     logger::debug!(mca_before_filtering=?all_mcas); | ||||
|     // filter out connectors based on the business country | ||||
|     let filtered_mcas = filter_mca_based_on_business_details(all_mcas, payment_intent.as_ref()); | ||||
|  | ||||
|     logger::debug!(mca_before_filtering=?filtered_mcas); | ||||
|  | ||||
|     let mut response: Vec<ResponsePaymentMethodIntermediate> = vec![]; | ||||
|     for mca in all_mcas { | ||||
|     for mca in filtered_mcas { | ||||
|         let payment_methods = match mca.payment_methods_enabled { | ||||
|             Some(pm) => pm, | ||||
|             None => continue, | ||||
| @ -874,6 +877,9 @@ pub async fn list_payment_methods( | ||||
|     let mut banks_consolidated_hm: HashMap<api_enums::PaymentMethodType, Vec<String>> = | ||||
|         HashMap::new(); | ||||
|  | ||||
|     let mut bank_debits_consolidated_hm = | ||||
|         HashMap::<api_enums::PaymentMethodType, Vec<String>>::new(); | ||||
|  | ||||
|     for element in response.clone() { | ||||
|         let payment_method = element.payment_method; | ||||
|         let payment_method_type = element.payment_method_type; | ||||
| @ -964,6 +970,17 @@ pub async fn list_payment_methods( | ||||
|                 banks_consolidated_hm.insert(element.payment_method_type, vec![connector]); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         if element.payment_method == api_enums::PaymentMethod::BankDebit { | ||||
|             let connector = element.connector.clone(); | ||||
|             if let Some(vector_of_connectors) = | ||||
|                 bank_debits_consolidated_hm.get_mut(&element.payment_method_type) | ||||
|             { | ||||
|                 vector_of_connectors.push(connector); | ||||
|             } else { | ||||
|                 bank_debits_consolidated_hm.insert(element.payment_method_type, vec![connector]); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     let mut payment_method_responses: Vec<ResponsePaymentMethodsEnabled> = vec![]; | ||||
| @ -983,6 +1000,7 @@ pub async fn list_payment_methods( | ||||
|                 payment_experience: Some(payment_experience_types), | ||||
|                 card_networks: None, | ||||
|                 bank_names: None, | ||||
|                 bank_debits: None, | ||||
|             }) | ||||
|         } | ||||
|  | ||||
| @ -1008,6 +1026,7 @@ pub async fn list_payment_methods( | ||||
|                 card_networks: Some(card_network_types), | ||||
|                 payment_experience: None, | ||||
|                 bank_names: None, | ||||
|                 bank_debits: None, | ||||
|             }) | ||||
|         } | ||||
|  | ||||
| @ -1017,26 +1036,52 @@ pub async fn list_payment_methods( | ||||
|         }) | ||||
|     } | ||||
|  | ||||
|     let mut bank_payment_method_types = vec![]; | ||||
|     let mut bank_redirect_payment_method_types = vec![]; | ||||
|  | ||||
|     for key in banks_consolidated_hm.iter() { | ||||
|         let payment_method_type = *key.0; | ||||
|         let connectors = key.1.clone(); | ||||
|         let bank_names = get_banks(state, payment_method_type, connectors)?; | ||||
|         bank_payment_method_types.push({ | ||||
|         bank_redirect_payment_method_types.push({ | ||||
|             ResponsePaymentMethodTypes { | ||||
|                 payment_method_type, | ||||
|                 bank_names: Some(bank_names), | ||||
|                 payment_experience: None, | ||||
|                 card_networks: None, | ||||
|                 bank_debits: None, | ||||
|             } | ||||
|         }) | ||||
|     } | ||||
|  | ||||
|     if !bank_payment_method_types.is_empty() { | ||||
|     if !bank_redirect_payment_method_types.is_empty() { | ||||
|         payment_method_responses.push(ResponsePaymentMethodsEnabled { | ||||
|             payment_method: api_enums::PaymentMethod::BankRedirect, | ||||
|             payment_method_types: bank_payment_method_types, | ||||
|             payment_method_types: bank_redirect_payment_method_types, | ||||
|         }); | ||||
|     } | ||||
|  | ||||
|     let mut bank_debit_payment_method_types = vec![]; | ||||
|  | ||||
|     for key in bank_debits_consolidated_hm.iter() { | ||||
|         let payment_method_type = *key.0; | ||||
|         let connectors = key.1.clone(); | ||||
|         bank_debit_payment_method_types.push({ | ||||
|             ResponsePaymentMethodTypes { | ||||
|                 payment_method_type, | ||||
|                 bank_names: None, | ||||
|                 payment_experience: None, | ||||
|                 card_networks: None, | ||||
|                 bank_debits: Some(api_models::payment_methods::BankDebitTypes { | ||||
|                     eligible_connectors: connectors, | ||||
|                 }), | ||||
|             } | ||||
|         }) | ||||
|     } | ||||
|  | ||||
|     if !bank_debit_payment_method_types.is_empty() { | ||||
|         payment_method_responses.push(ResponsePaymentMethodsEnabled { | ||||
|             payment_method: api_enums::PaymentMethod::BankDebit, | ||||
|             payment_method_types: bank_debit_payment_method_types, | ||||
|         }); | ||||
|     } | ||||
|  | ||||
| @ -1169,6 +1214,25 @@ async fn filter_payment_methods( | ||||
|     Ok(()) | ||||
| } | ||||
|  | ||||
| fn filter_mca_based_on_business_details( | ||||
|     merchant_connector_accounts: Vec< | ||||
|         storage_models::merchant_connector_account::MerchantConnectorAccount, | ||||
|     >, | ||||
|     payment_intent: Option<&storage_models::payment_intent::PaymentIntent>, | ||||
| ) -> Vec<storage_models::merchant_connector_account::MerchantConnectorAccount> { | ||||
|     if let Some(payment_intent) = payment_intent { | ||||
|         merchant_connector_accounts | ||||
|             .into_iter() | ||||
|             .filter(|mca| { | ||||
|                 mca.business_country == payment_intent.business_country | ||||
|                     && mca.business_label == payment_intent.business_label | ||||
|             }) | ||||
|             .collect::<Vec<_>>() | ||||
|     } else { | ||||
|         merchant_connector_accounts | ||||
|     } | ||||
| } | ||||
|  | ||||
| fn filter_pm_based_on_config<'a>( | ||||
|     config: &'a crate::configs::settings::ConnectorFilters, | ||||
|     connector: &'a str, | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 Narayan Bhat
					Narayan Bhat