mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-01 02:57:02 +08:00
fix(filter_mca): update helper function for filtering MCAs for payments (#5529)
This commit is contained in:
@ -19,7 +19,7 @@ use api_models::{
|
||||
pm_auth::PaymentMethodAuthConfig,
|
||||
surcharge_decision_configs as api_surcharge_decision_configs,
|
||||
};
|
||||
use common_enums::enums::MerchantStorageScheme;
|
||||
use common_enums::{enums::MerchantStorageScheme, ConnectorType};
|
||||
use common_utils::{
|
||||
consts,
|
||||
crypto::Encryptable,
|
||||
@ -2368,9 +2368,12 @@ pub async fn list_payment_methods(
|
||||
)
|
||||
.await?;
|
||||
|
||||
// filter out connectors based on the business country
|
||||
let filtered_mcas =
|
||||
helpers::filter_mca_based_on_business_profile(all_mcas.clone(), profile_id.clone());
|
||||
// filter out payment connectors based on profile_id
|
||||
let filtered_mcas = helpers::filter_mca_based_on_profile_and_connector_type(
|
||||
all_mcas.clone(),
|
||||
profile_id.as_ref(),
|
||||
ConnectorType::PaymentProcessor,
|
||||
);
|
||||
|
||||
logger::debug!(mca_before_filtering=?filtered_mcas);
|
||||
|
||||
|
||||
@ -121,31 +121,18 @@ pub fn create_certificate(
|
||||
.change_context(errors::ApiClientError::CertificateDecodeFailed)
|
||||
}
|
||||
|
||||
pub fn filter_mca_based_on_business_profile(
|
||||
merchant_connector_accounts: Vec<domain::MerchantConnectorAccount>,
|
||||
profile_id: Option<String>,
|
||||
) -> Vec<domain::MerchantConnectorAccount> {
|
||||
if let Some(profile_id) = profile_id {
|
||||
merchant_connector_accounts
|
||||
.into_iter()
|
||||
.filter(|mca| {
|
||||
mca.profile_id.as_ref() == Some(&profile_id)
|
||||
&& mca.connector_type == ConnectorType::PaymentProcessor
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
} else {
|
||||
merchant_connector_accounts
|
||||
}
|
||||
}
|
||||
|
||||
pub fn filter_mca_based_on_connector_type(
|
||||
pub fn filter_mca_based_on_profile_and_connector_type(
|
||||
merchant_connector_accounts: Vec<domain::MerchantConnectorAccount>,
|
||||
profile_id: Option<&String>,
|
||||
connector_type: ConnectorType,
|
||||
) -> Vec<domain::MerchantConnectorAccount> {
|
||||
merchant_connector_accounts
|
||||
.into_iter()
|
||||
.filter(|mca| mca.connector_type == connector_type)
|
||||
.collect::<Vec<_>>()
|
||||
.filter(|mca| {
|
||||
profile_id.map_or(true, |id| mca.profile_id.as_ref() == Some(id))
|
||||
&& mca.connector_type == connector_type
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
#[instrument(skip_all)]
|
||||
@ -4299,10 +4286,12 @@ where
|
||||
.await
|
||||
.to_not_found_response(errors::ApiErrorResponse::InternalServerError)?;
|
||||
|
||||
let profile_specific_merchant_connector_account_list = filter_mca_based_on_business_profile(
|
||||
merchant_connector_account_list,
|
||||
Some(profile_id.to_string()),
|
||||
);
|
||||
let profile_specific_merchant_connector_account_list =
|
||||
filter_mca_based_on_profile_and_connector_type(
|
||||
merchant_connector_account_list,
|
||||
Some(profile_id),
|
||||
ConnectorType::PaymentProcessor,
|
||||
);
|
||||
|
||||
let mut connector_data_list = vec![pre_decided_connector_data_first.clone()];
|
||||
|
||||
|
||||
@ -375,8 +375,11 @@ where
|
||||
.change_context(errors::ApiErrorResponse::InternalServerError)
|
||||
.attach_printable("profile_id is not set in payment_intent")?;
|
||||
|
||||
let filtered_connector_accounts =
|
||||
helpers::filter_mca_based_on_business_profile(all_connector_accounts, Some(profile_id));
|
||||
let filtered_connector_accounts = helpers::filter_mca_based_on_profile_and_connector_type(
|
||||
all_connector_accounts,
|
||||
Some(&profile_id),
|
||||
common_enums::ConnectorType::PaymentProcessor,
|
||||
);
|
||||
|
||||
let requested_payment_method_types = request.wallets.clone();
|
||||
let mut connector_and_supporting_payment_method_type = Vec::new();
|
||||
|
||||
@ -560,10 +560,18 @@ pub async fn refresh_cgraph_cache<'a>(
|
||||
}
|
||||
};
|
||||
|
||||
let merchant_connector_accounts = payments_oss::helpers::filter_mca_based_on_business_profile(
|
||||
merchant_connector_accounts,
|
||||
profile_id,
|
||||
);
|
||||
let connector_type = match transaction_type {
|
||||
api_enums::TransactionType::Payment => common_enums::ConnectorType::PaymentProcessor,
|
||||
#[cfg(feature = "payouts")]
|
||||
api_enums::TransactionType::Payout => common_enums::ConnectorType::PayoutProcessor,
|
||||
};
|
||||
|
||||
let merchant_connector_accounts =
|
||||
payments_oss::helpers::filter_mca_based_on_profile_and_connector_type(
|
||||
merchant_connector_accounts,
|
||||
profile_id.as_ref(),
|
||||
connector_type,
|
||||
);
|
||||
|
||||
let api_mcas = merchant_connector_accounts
|
||||
.into_iter()
|
||||
|
||||
@ -278,12 +278,10 @@ pub async fn filter_payout_methods(
|
||||
)
|
||||
.await
|
||||
.to_not_found_response(errors::ApiErrorResponse::MerchantAccountNotFound)?;
|
||||
// fetch all mca based on profile id
|
||||
let filtered_mca_on_profile =
|
||||
helpers::filter_mca_based_on_business_profile(all_mcas, Some(payout.profile_id.clone()));
|
||||
//Since we just need payout connectors here, filter mca based on connector type.
|
||||
let filtered_mca = helpers::filter_mca_based_on_connector_type(
|
||||
filtered_mca_on_profile.clone(),
|
||||
// Filter MCAs based on profile_id and connector_type
|
||||
let filtered_mcas = helpers::filter_mca_based_on_profile_and_connector_type(
|
||||
all_mcas,
|
||||
Some(&payout.profile_id),
|
||||
common_enums::ConnectorType::PayoutProcessor,
|
||||
);
|
||||
let address = db
|
||||
@ -306,7 +304,7 @@ pub async fn filter_payout_methods(
|
||||
let mut card_hash_set: HashSet<common_enums::PaymentMethodType> = HashSet::new();
|
||||
let mut wallet_hash_set: HashSet<common_enums::PaymentMethodType> = HashSet::new();
|
||||
let payout_filter_config = &state.conf.payout_method_filters.clone();
|
||||
for mca in &filtered_mca {
|
||||
for mca in &filtered_mcas {
|
||||
let payout_methods = match &mca.payment_methods_enabled {
|
||||
Some(pm) => pm,
|
||||
None => continue,
|
||||
|
||||
Reference in New Issue
Block a user