-
Notifications
You must be signed in to change notification settings - Fork 34
EUL-21012 added currency check for UPi txn #199
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -3092,9 +3092,10 @@ pub async fn filterGatewaysForUpi(this: &mut DeciderFlow<'_>) -> Vec<String> { | |||||||||||||||||
| .collect(); | ||||||||||||||||||
|
|
||||||||||||||||||
| //Convert upi_only_gateways to <HashSet<_>> | ||||||||||||||||||
| let upi_only_gateways_hashset = upi_only_gateways.into_iter().collect::<HashSet<_>>(); | ||||||||||||||||||
| let upi_only_gateways_hashset = upi_only_gateways.clone().into_iter().collect::<HashSet<_>>(); | ||||||||||||||||||
|
|
||||||||||||||||||
| if txn_card_info.paymentMethodType == UPI { | ||||||||||||||||||
| let txn_currency = txn_detail.currency.clone(); | ||||||||||||||||||
| let upi_also_gateway: Vec<String> = | ||||||||||||||||||
| findByNameFromRedis::<Vec<String>>(C::UpiAlsoGateways.get_key()) | ||||||||||||||||||
| .await | ||||||||||||||||||
|
|
@@ -3107,12 +3108,24 @@ pub async fn filterGatewaysForUpi(this: &mut DeciderFlow<'_>) -> Vec<String> { | |||||||||||||||||
| .union(&upi_also_gateway_hashset) | ||||||||||||||||||
| .cloned() | ||||||||||||||||||
| .collect::<HashSet<_>>(); | ||||||||||||||||||
| setGws( | ||||||||||||||||||
| this, | ||||||||||||||||||
| st.into_iter() | ||||||||||||||||||
| .filter(|gateway| upi_support_gateways.contains(gateway)) | ||||||||||||||||||
| .collect(), | ||||||||||||||||||
| ); | ||||||||||||||||||
|
|
||||||||||||||||||
| let mut filtered_gws = st.into_iter() | ||||||||||||||||||
| .filter(|gateway| upi_support_gateways.contains(gateway)) | ||||||||||||||||||
| .collect::<Vec<_>>(); | ||||||||||||||||||
|
|
||||||||||||||||||
| // Filter for non-INR UPI transactions based on supported currencies | ||||||||||||||||||
| if txn_currency != Currency::INR { | ||||||||||||||||||
| filtered_gws = filter_upi_gateways_for_currency( | ||||||||||||||||||
| this, | ||||||||||||||||||
| filtered_gws, | ||||||||||||||||||
| upi_only_gateways, | ||||||||||||||||||
| txn_currency, | ||||||||||||||||||
| &txn_card_info, | ||||||||||||||||||
| ) | ||||||||||||||||||
| .await; | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| setGws(this, filtered_gws); | ||||||||||||||||||
| } else if !SUTC::is_google_pay_txn(txn_card_info) { | ||||||||||||||||||
| setGws( | ||||||||||||||||||
| this, | ||||||||||||||||||
|
|
@@ -3131,6 +3144,90 @@ pub async fn filterGatewaysForUpi(this: &mut DeciderFlow<'_>) -> Vec<String> { | |||||||||||||||||
| ) | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| async fn filter_upi_gateways_for_currency( | ||||||||||||||||||
| this: &mut DeciderFlow<'_>, | ||||||||||||||||||
| upi_gateways: Vec<String>, | ||||||||||||||||||
| all_upi_gateways: Vec<String>, | ||||||||||||||||||
| txn_currency: Currency, | ||||||||||||||||||
| txn_card_info: &TxnCardInfo, | ||||||||||||||||||
| ) -> Vec<String> { | ||||||||||||||||||
| // Get payment method entry from database | ||||||||||||||||||
| let pm_entry = ETP::get_by_name(txn_card_info.paymentMethod.clone()).await; | ||||||||||||||||||
|
|
||||||||||||||||||
| match pm_entry { | ||||||||||||||||||
| Some(pm) => { | ||||||||||||||||||
| // Get all MGAs for the merchant | ||||||||||||||||||
| let mgas = Utils::get_mgas(this).unwrap_or_default(); | ||||||||||||||||||
|
|
||||||||||||||||||
| // Filter MGAs to only those supporting UPI gateways | ||||||||||||||||||
| let upi_gateway_set: HashSet<String> = all_upi_gateways.iter().cloned().collect(); | ||||||||||||||||||
| let upi_mgas: Vec<_> = mgas | ||||||||||||||||||
| .into_iter() | ||||||||||||||||||
| .filter(|mga| upi_gateway_set.contains(&mga.gateway)) | ||||||||||||||||||
| .collect(); | ||||||||||||||||||
|
|
||||||||||||||||||
| // Filter gateways based on supported currencies | ||||||||||||||||||
| let currency_supported_gws: Vec<String> = upi_gateways | ||||||||||||||||||
| .iter() | ||||||||||||||||||
| .filter(|gw| { | ||||||||||||||||||
| // Find the MGA for this gateway | ||||||||||||||||||
| if let Some(mga) = upi_mgas.iter().find(|mga| &mga.gateway == *gw) { | ||||||||||||||||||
| // Check if the MGA has supported currencies configured | ||||||||||||||||||
| if let Some(ref supported_currencies_str) = mga.supportedCurrencies { | ||||||||||||||||||
| // Parse the supported currencies JSON array | ||||||||||||||||||
| match serde_json::from_str::<Vec<String>>(supported_currencies_str) { | ||||||||||||||||||
| Ok(currency_list) => { | ||||||||||||||||||
| // Convert currency strings to Currency enum and check if txn_currency is supported | ||||||||||||||||||
| currency_list.iter().any(|curr_str| { | ||||||||||||||||||
| Currency::text_to_curr(curr_str) | ||||||||||||||||||
| .map(|curr| curr == txn_currency) | ||||||||||||||||||
| .unwrap_or(false) | ||||||||||||||||||
| }) | ||||||||||||||||||
|
Comment on lines
+3180
to
+3185
|
||||||||||||||||||
| // Convert currency strings to Currency enum and check if txn_currency is supported | |
| currency_list.iter().any(|curr_str| { | |
| Currency::text_to_curr(curr_str) | |
| .map(|curr| curr == txn_currency) | |
| .unwrap_or(false) | |
| }) | |
| // Use the existing canAcceptCurrency function for consistency | |
| canAcceptCurrency(¤cy_list, txn_currency) |
Copilot
AI
Dec 16, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When supportedCurrencies is None for a gateway, the code returns false and filters out that gateway. This differs from the behavior in the existing currencyFilter function (line 542-548) which defaults to allowing INR when supportedCurrencies is not set. This inconsistency means gateways without configured currencies will be rejected for non-INR transactions even if they might support INR by default. Consider aligning this behavior with the existing currency filtering logic.
| false | |
| // If supportedCurrencies is not set, allow INR by default (for consistency with currencyFilter) | |
| txn_currency == Currency::INR |
Copilot
AI
Dec 16, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function lacks documentation. Consider adding a docstring that explains the purpose, parameters, return value, and the currency filtering logic, especially noting that it returns an empty vector when payment method is not found or when gateways don't support the transaction currency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
.clone()added here is unnecessary. The original code consumedupi_only_gatewaysby converting it into an iterator and then collecting into a HashSet. However,upi_only_gatewaysis now used again at line 3121. Instead of cloning the entire vector here, consider collecting into the HashSet first, then cloning from the HashSet when needed, or restructure to avoid the need for cloning altogether by reordering operations.