diff --git a/crates/router/src/core/payment_methods/cards.rs b/crates/router/src/core/payment_methods/cards.rs index 7e68eb23d5..1249470210 100644 --- a/crates/router/src/core/payment_methods/cards.rs +++ b/crates/router/src/core/payment_methods/cards.rs @@ -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); diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rs index 6efba6aa81..d29cfbf100 100644 --- a/crates/router/src/core/payments/helpers.rs +++ b/crates/router/src/core/payments/helpers.rs @@ -91,12 +91,12 @@ pub fn create_identity_from_certificate_and_key( pub fn filter_mca_based_on_business_profile( merchant_connector_accounts: Vec, - payment_intent: Option<&PaymentIntent>, + profile_id: Option, ) -> Vec { - 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::>() } else { merchant_connector_accounts diff --git a/crates/router/src/core/payments/operations/payment_session.rs b/crates/router/src/core/payments/operations/payment_session.rs index a37dbfcf2e..70d8c36f2f 100644 --- a/crates/router/src/core/payments/operations/payment_session.rs +++ b/crates/router/src/core/payments/operations/payment_session.rs @@ -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();