Skip to content

Conversation

@ShankarSinghC
Copy link
Collaborator

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:

  • The main logic now uses 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.
  • Added the new method 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:

  • The previous percentage-based savings method has been renamed to calculate_network_saving_infos_with_savings_as_percentage and marked as dead code, indicating it is no longer used.

** Test Case **
Request

{
    "merchantId": "merc_1757410925",
    "eligibleGatewayList": null,
    "rankingAlgorithm": "NTW_BASED_ROUTING",
    "eliminationEnabled": true,
    "paymentInfo": {
        "paymentId": "PAY12500",
        "amount": 20000,
        "currency": "USD",
        "customerId": "CUST12345",
        "udfs": null,
        "preferredGateway": null,
        "paymentType": "MOTO_PAYMENT",
        "metadata": "{\"merchant_category_code\":\"merchant_category_code_0001\",\"acquirer_country\":\"US\"}",
        "internalMetadata": null,
        "isEmi": false,
        "emiBank": null,
        "emiTenure": null,
        "paymentMethodType": "CARD",
        "paymentMethod": "VISA",
        "paymentSource": null,
        "authType": null,
        "cardIssuerBankName": null,
        "cardIsin": "440000",
        "cardType": null,
        "cardSwitchProvider": null
    }
}

Response

{
    "decided_gateway": "",
    "gateway_priority_map": null,
    "filter_wise_gateways": null,
    "priority_logic_tag": null,
    "routing_approach": "NTW_BASED_ROUTING",
    "gateway_before_evaluation": null,
    "priority_logic_output": null,
    "debit_routing_output": {
        "co_badged_card_networks_info": [
            {
                "network": "ACCEL",
                "saving_percentage": 25.5
            },
            {
                "network": "STAR",
                "saving_percentage": 8.0
            },
            {
                "network": "VISA",
                "saving_percentage": 0.0
            }
        ],
        "issuer_country": "US",
        "is_regulated": true,
        "regulated_name": "GOVERNMENT EXEMPT INTERCHANGE FEE",
        "card_type": "debit"
    },
    "reset_approach": "NO_RESET",
    "routing_dimension": null,
    "routing_dimension_level": null,
    "is_scheduled_outage": false,
    "is_dynamic_mga_enabled": false,
    "gateway_mga_id_map": null,
    "is_rust_based_decider": true
}

@ShankarSinghC ShankarSinghC self-assigned this Sep 18, 2025
Copilot AI review requested due to automatic review settings September 18, 2025 10:05
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +142 to +146
// 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);
Copy link

Copilot AI Sep 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
// 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();

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants