mirror of
				https://github.com/juspay/hyperswitch.git
				synced 2025-11-01 02:57:02 +08:00 
			
		
		
		
	refactor(pm_list): get profile_id from business_details in list pm (#2131)
This commit is contained in:
		| @ -854,9 +854,24 @@ pub async fn list_payment_methods( | ||||
|         .await | ||||
|         .to_not_found_response(errors::ApiErrorResponse::MerchantAccountNotFound)?; | ||||
|  | ||||
|     let profile_id = payment_intent | ||||
|         .as_ref() | ||||
|         .async_map(|payment_intent| async { | ||||
|             crate::core::utils::get_profile_id_from_business_details( | ||||
|                 payment_intent.business_country, | ||||
|                 payment_intent.business_label.as_ref(), | ||||
|                 &merchant_account, | ||||
|                 payment_intent.profile_id.as_ref(), | ||||
|                 db, | ||||
|             ) | ||||
|             .await | ||||
|             .attach_printable("Could not find profile id from business details") | ||||
|         }) | ||||
|         .await | ||||
|         .transpose()?; | ||||
|  | ||||
|     // filter out connectors based on the business country | ||||
|     let filtered_mcas = | ||||
|         helpers::filter_mca_based_on_business_profile(all_mcas, payment_intent.as_ref()); | ||||
|     let filtered_mcas = helpers::filter_mca_based_on_business_profile(all_mcas, profile_id); | ||||
|  | ||||
|     logger::debug!(mca_before_filtering=?filtered_mcas); | ||||
|  | ||||
|  | ||||
| @ -91,12 +91,12 @@ pub fn create_identity_from_certificate_and_key( | ||||
|  | ||||
| pub fn filter_mca_based_on_business_profile( | ||||
|     merchant_connector_accounts: Vec<domain::MerchantConnectorAccount>, | ||||
|     payment_intent: Option<&PaymentIntent>, | ||||
|     profile_id: Option<String>, | ||||
| ) -> Vec<domain::MerchantConnectorAccount> { | ||||
|     if let Some(payment_intent) = payment_intent { | ||||
|     if let Some(profile_id) = profile_id { | ||||
|         merchant_connector_accounts | ||||
|             .into_iter() | ||||
|             .filter(|mca| mca.profile_id == payment_intent.profile_id) | ||||
|             .filter(|mca| mca.profile_id.as_ref() == Some(&profile_id)) | ||||
|             .collect::<Vec<_>>() | ||||
|     } else { | ||||
|         merchant_connector_accounts | ||||
|  | ||||
| @ -330,10 +330,18 @@ where | ||||
|             .change_context(errors::ApiErrorResponse::InternalServerError) | ||||
|             .attach_printable("Database error when querying for merchant connector accounts")?; | ||||
|  | ||||
|         let filtered_connector_accounts = helpers::filter_mca_based_on_business_profile( | ||||
|             all_connector_accounts, | ||||
|             Some(payment_intent), | ||||
|         ); | ||||
|         let profile_id = crate::core::utils::get_profile_id_from_business_details( | ||||
|             payment_intent.business_country, | ||||
|             payment_intent.business_label.as_ref(), | ||||
|             merchant_account, | ||||
|             payment_intent.profile_id.as_ref(), | ||||
|             &*state.store, | ||||
|         ) | ||||
|         .await | ||||
|         .attach_printable("Could not find profile id from business details")?; | ||||
|  | ||||
|         let filtered_connector_accounts = | ||||
|             helpers::filter_mca_based_on_business_profile(all_connector_accounts, Some(profile_id)); | ||||
|  | ||||
|         let requested_payment_method_types = request.wallets.clone(); | ||||
|         let mut connector_and_supporting_payment_method_type = Vec::new(); | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 Narayan Bhat
					Narayan Bhat