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