Skip to content

feat: adding more dimensional granularity for scoring #106

Merged
jagan-jaya merged 13 commits into
mainfrom
add-de-dimensions
Jul 28, 2025
Merged

feat: adding more dimensional granularity for scoring #106
jagan-jaya merged 13 commits into
mainfrom
add-de-dimensions

Conversation

@GauravRawat369
Copy link
Copy Markdown
Contributor

@GauravRawat369 GauravRawat369 commented Jul 8, 2025

The decision engine currently supports only payment_method and payment_method_type.

  • This pr adds more parameters like:
  1. Card Network
  2. Currency
  3. Auth type
  4. Card Bin (cardIsin)
  5. Country
  • This pr also adds a function config_sr_dimensions which allows us to configure dimensions on the merchant level

  • Created a new service_configuration SR_DIMENSION_CONFIG_merchant_123 which will look like {"merchant_id":"merchant_1752591820","fields":["paymentInfo.currency","paymentInfo.country","paymentInfo.auth_type"]}

Request (config_sr_dimensions)

curl --location 'http://localhost:8082/config-sr-dimension' \
--header 'Content-Type: application/json' \
--data '{
    "merchant_id": "merchant_1752591820",
    "fields": ["paymentInfo.currency", "paymentInfo.country", "paymentInfo.auth_type"]
}'

Response (config_sr_dimensions)

If the SR Dimension is configured correctly

"SR Dimension configuration updated successfully"

If the SR Dimension is not configured correctly

{
    "code": "TE_04",
    "message": "Invalid dimensions: 'paymentInfo.authType'. Valid dimensions are: paymentInfo.currency, paymentInfo.country, paymentInfo.auth_type, paymentInfo.card_is_in, paymentInfo.card_network",
    "data": null
}

The current get_unified_sr_key function is used for creating the keys for the Redis
But in the current setup

  1. enforce1d is always false
  2. isPaymentSourceEnabledForSrRouting is always false
  3. isAuthLevelEnabledForSrRouting is always false
  4. isBankLevelEnabledForSrRouting is always false
  5. cardType is none

So that means get_unified_sr_key function is only creating new keys based on pm and pmt via intercalate_without_empty_string("_", &base_key)

How do I test it?

curl --location 'http://localhost:8080/decide-gateway' \
--header 'Content-Type: application/json' \
--data '{           
        "merchantId": "merchant_abcdefg",
        "eligibleGatewayList": ["GatewayA", "GatewayB", "GatewayC"],
        "rankingAlgorithm": "SR_BASED_ROUTING",
        "eliminationEnabled": false,
        "paymentInfo": {
            "paymentId": "PAY12359",
            "amount": 100.50,
            "currency": "USD",
            "country": "NL", //new parameter
            "customerId": "CUST12345",
            "udfs": null,
            "preferredGateway": null,
            "paymentType": "ORDER_PAYMENT",
            "metadata": null,
            "internalMetadata": null,
            "isEmi": false,
            "emiBank": null,
            "emiTenure": null,
            "paymentMethodType": "UPI",
            "paymentMethod": "UPI_COLLECT",
            "paymentSource": null,
            "authType": "OTP",
            "cardIssuerBankName": null,
            "cardIsin": "424242",
            "cardType": null,
            "cardSwitchProvider": "visa"
        }
}'

so here

  1. Card Network is visa
  2. Currency is USD
  3. Auth type is OTP
  4. Card Bin (cardIsin) is 424242
  5. Country is NL

So the keys that are generated after these changes are

image

keys that are generated before these changes, with the same curl are(only have pm and pmt)

image

How do I test with config_sr_dimensions?

We will change the config for the merchant, let's remove the country from SR_DIMENSION_CONFIG_merchant_abcdefg

image

The country dimension is removed from SR_DIMENSION_CONFIG_merchant_1752591820

SR_DIMENSION_CONFIG_merchant_abcdefg | {"merchant_id":"merchant_abcdefg","fields":["paymentInfo.currency","paymentInfo.card_is_in","paymentInfo.auth_type","paymentInfo.card_network"]}

@GauravRawat369 GauravRawat369 self-assigned this Jul 8, 2025
Copilot AI review requested due to automatic review settings July 8, 2025 11:01
Copy link
Copy Markdown
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 enhances the SRv3 scoring engine by adding four new dimensions—card network, currency, auth type, and card bin—to both the scoring lookup functions and the Redis key generation logic.

  • Extract and propagate new parameters (cardSwitchProvider, card_isin, currency, authType) through all SRv3 scoring flows
  • Extend get_sr_v3_* and get_sr_v3_sub_level_input_config to filter by the new dimensions
  • Update get_unified_sr_key to append optional fields when present, with a legacy fallback when none are provided

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/feedback/gateway_selection_scoring_v3/flow.rs Extract new parameters in getSrV3MerchantBucketSize and pass them to get_sr_v3_bucket_size
src/feedback/gateway_scoring_service.rs Inject new parameters into get_sr_v3_latency_threshold calls
src/decider/gatewaydecider/utils.rs Update signatures of all get_sr_v3_* functions, add is_sr_v3_config_match, extend key gen
src/decider/gatewaydecider/types.rs Add cardIsIn, cardSwitchProvider, currency fields to GatewayScoringData and state
src/decider/gatewaydecider/gw_scoring.rs Pass new parameters into hedging, bucket size, reset factor, and extra‐score methods
Comments suppressed due to low confidence (2)

src/decider/gatewaydecider/utils.rs:1565

  • [nitpick] All get_sr_v3_* functions take owned Option<String> parameters and clone them in every call. To avoid repeated allocations, consider passing &Option<String> and using references for matching.
    card_network: Option<String>,

src/decider/gatewaydecider/utils.rs:2461

  • [nitpick] The legacy-fallback branch in get_unified_sr_key is important for backward compatibility. Adding a comment or docblock to explain why and when this fallback is used would help future maintainers.
    if card_network.is_none() && card_isin.is_none() && currency.is_none() && auth_type.is_none() {

Comment thread src/feedback/gateway_selection_scoring_v3/flow.rs
Comment thread src/decider/gatewaydecider/utils.rs Outdated
@GauravRawat369 GauravRawat369 changed the title Adding more dimensional granularity for scoring feat: adding more dimensional granularity for scoring Jul 11, 2025
Comment thread src/decider/gatewaydecider/gw_scoring.rs Outdated
Comment thread src/decider/gatewaydecider/gw_scoring.rs Outdated
Comment thread src/decider/gatewaydecider/gw_scoring.rs Outdated
Comment thread src/decider/gatewaydecider/gw_scoring.rs Outdated
Comment thread src/decider/gatewaydecider/gw_scoring.rs Outdated
Comment thread src/types/country/country_iso.rs Outdated
jagan-jaya
jagan-jaya previously approved these changes Jul 28, 2025
Comment thread src/decider/gatewaydecider/utils.rs Outdated
@jagan-jaya jagan-jaya merged commit bb8acfe into main Jul 28, 2025
5 of 6 checks passed
@jagan-jaya jagan-jaya deleted the add-de-dimensions branch July 28, 2025 11:07
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.

Create an endpoint in DE to accept above dimension as config for SR bucket creation for a merchant

5 participants