refactor(debit_routing): make the savings as the absolute value#154
refactor(debit_routing): make the savings as the absolute value#154ShankarSinghC wants to merge 1 commit intomainfrom
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR refactors network savings calculation for debit routing from percentage-based to absolute value-based savings. The change aims to provide more meaningful savings information by calculating the absolute difference between each network's fee and the most expensive fee, rather than percentage savings relative to transaction amount.
- Replaced percentage-based savings calculation with absolute value calculation
- Added new method
calculate_network_saving_infos_with_savings_as_absolute_value - Deprecated the old percentage-based method by marking it as dead code
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| // Sort the network costs by fee | ||
| network_costs.sort_by(|(_, fee1), (_, fee2)| fee1.total_cmp(fee2)); | ||
|
|
||
| // Get the most expensive fee | ||
| let most_expensive_fee = network_costs.last().map(|(_, fee)| *fee).unwrap_or(0.0); |
There was a problem hiding this comment.
Using unwrap_or(0.0) when network_costs is empty will result in all savings being calculated as negative values (0.0 - fee). This could lead to incorrect savings calculations. Consider returning early or handling the empty case explicitly.
| // Sort the network costs by fee | |
| network_costs.sort_by(|(_, fee1), (_, fee2)| fee1.total_cmp(fee2)); | |
| // Get the most expensive fee | |
| let most_expensive_fee = network_costs.last().map(|(_, fee)| *fee).unwrap_or(0.0); | |
| // Return early if network_costs is empty | |
| if network_costs.is_empty() { | |
| return Vec::new(); | |
| } | |
| // Sort the network costs by fee | |
| network_costs.sort_by(|(_, fee1), (_, fee2)| fee1.total_cmp(fee2)); | |
| // Get the most expensive fee | |
| let most_expensive_fee = network_costs.last().map(|(_, fee)| *fee).unwrap(); |
This pull request refactors how network savings information is calculated for co-badged card requests, shifting the calculation from percentage-based savings to absolute value-based savings. It introduces a new method for computing savings as absolute values, updates the main logic to use this method, and marks the previous percentage-based approach as deprecated.
Network savings calculation changes:
calculate_network_saving_infos_with_savings_as_absolute_value, which computes savings as the absolute difference between each network's fee and the most expensive fee, instead of using percentage savings.calculate_network_saving_infos_with_savings_as_absolute_value, which sorts the network costs, finds the highest fee, and calculates the savings for each network as an absolute value.Deprecation of old logic:
calculate_network_saving_infos_with_savings_as_percentageand marked as dead code, indicating it is no longer used.** Test Case **
Request
Response