refactor(pm_list): get profile_id from business_details in list pm (#2131)

This commit is contained in:
Narayan Bhat
2023-09-12 17:20:59 +05:30
committed by GitHub
parent a3dd8b7d1e
commit 90868b93d6
3 changed files with 32 additions and 9 deletions

View File

@ -854,9 +854,24 @@ pub async fn list_payment_methods(
.await .await
.to_not_found_response(errors::ApiErrorResponse::MerchantAccountNotFound)?; .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 // filter out connectors based on the business country
let filtered_mcas = let filtered_mcas = helpers::filter_mca_based_on_business_profile(all_mcas, profile_id);
helpers::filter_mca_based_on_business_profile(all_mcas, payment_intent.as_ref());
logger::debug!(mca_before_filtering=?filtered_mcas); logger::debug!(mca_before_filtering=?filtered_mcas);

View File

@ -91,12 +91,12 @@ pub fn create_identity_from_certificate_and_key(
pub fn filter_mca_based_on_business_profile( pub fn filter_mca_based_on_business_profile(
merchant_connector_accounts: Vec<domain::MerchantConnectorAccount>, merchant_connector_accounts: Vec<domain::MerchantConnectorAccount>,
payment_intent: Option<&PaymentIntent>, profile_id: Option<String>,
) -> Vec<domain::MerchantConnectorAccount> { ) -> Vec<domain::MerchantConnectorAccount> {
if let Some(payment_intent) = payment_intent { if let Some(profile_id) = profile_id {
merchant_connector_accounts merchant_connector_accounts
.into_iter() .into_iter()
.filter(|mca| mca.profile_id == payment_intent.profile_id) .filter(|mca| mca.profile_id.as_ref() == Some(&profile_id))
.collect::<Vec<_>>() .collect::<Vec<_>>()
} else { } else {
merchant_connector_accounts merchant_connector_accounts

View File

@ -330,10 +330,18 @@ where
.change_context(errors::ApiErrorResponse::InternalServerError) .change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Database error when querying for merchant connector accounts")?; .attach_printable("Database error when querying for merchant connector accounts")?;
let filtered_connector_accounts = helpers::filter_mca_based_on_business_profile( let profile_id = crate::core::utils::get_profile_id_from_business_details(
all_connector_accounts, payment_intent.business_country,
Some(payment_intent), 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 requested_payment_method_types = request.wallets.clone();
let mut connector_and_supporting_payment_method_type = Vec::new(); let mut connector_and_supporting_payment_method_type = Vec::new();