Skip to content

feat(dynamic_routing): Decision engine config API integration #8044

Merged
likhinbopanna merged 21 commits intomainfrom
decision-engine-config
May 22, 2025
Merged

feat(dynamic_routing): Decision engine config API integration #8044
likhinbopanna merged 21 commits intomainfrom
decision-engine-config

Conversation

@Sarthak1799
Copy link
Contributor

@Sarthak1799 Sarthak1799 commented May 15, 2025

Type of Change

  • Bugfix
  • New feature
  • Enhancement
  • Refactoring
  • Dependency updates
  • Documentation
  • CI/CD

Description

This PR integrates the decision engine config APIs
The integration sits in the dynamic routing config flows. Based on ENV, if decision engine is enabled, we would call DE instead of Dynamo.

Additional Changes

  • This PR modifies the API contract
  • This PR modifies the database schema
  • This PR modifies application configuration/environment variables

Motivation and Context

How did you test it?

  1. Create a merchant account (Call to Decision Engine should be made for merchant creation)
image
  1. Toggle SR config (Call to Decision Engine should be made for SR config creation)
curl --location --request POST 'http://localhost:8080/account/merchant_1747841259/business_profile/pro_GUovaynfuaBwH3DUaBbJ/dynamic_routing/success_based/toggle?enable=dynamic_connector_selection' \
--header 'api-key: dev_9gwSrzjH1Xbs7HMswLgx0Av8upsibfu8wORNxyzpIls3NvT08auKe4RBQlkBgqRl'
{"id":"routing_wd4JSbjaMmLDB96OxP7d","profile_id":"pro_GUovaynfuaBwH3DUaBbJ","name":"Success rate based dynamic routing algorithm","kind":"dynamic","description":"","created_at":1747841362,"modified_at":1747841362,"algorithm_for":"payment","decision_engine_routing_id":null}
image
  1. Update SR config
curl --location --request PATCH 'http://localhost:8080/account/merchant_1747841259/business_profile/pro_GUovaynfuaBwH3DUaBbJ/dynamic_routing/success_based/config/routing_wd4JSbjaMmLDB96OxP7d' \
--header 'api-key: dev_9gwSrzjH1Xbs7HMswLgx0Av8upsibfu8wORNxyzpIls3NvT08auKe4RBQlkBgqRl' \
--header 'Content-Type: application/json' \
--data '{
    "decision_engine_configs": {
        "defaultLatencyThreshold": 90,
        "defaultSuccessRate": 0.5,
        "defaultBucketSize": 200,
        "defaultHedgingPercent": 5,
        "subLevelInputConfig": [
            {
                "paymentMethodType": "upi",
                "paymentMethod": "upi_collect",
                "bucketSize": 250,
                "hedgingPercent": 1
            }
        ]
    }
}'
{"id":"routing_tgng0ubQwdK3hSaSjRye","profile_id":"pro_GUovaynfuaBwH3DUaBbJ","name":"Success rate based dynamic routing algorithm","kind":"dynamic","description":"","created_at":1747841498,"modified_at":1747841498,"algorithm_for":"payment","decision_engine_routing_id":null}
  1. Activate updated SR config (Call to Decision Engine should be made for SR config updation)
curl --location --request POST 'http://localhost:8080/routing/routing_tgng0ubQwdK3hSaSjRye/activate' \
--header 'api-key: dev_9gwSrzjH1Xbs7HMswLgx0Av8upsibfu8wORNxyzpIls3NvT08auKe4RBQlkBgqRl'
image
  1. Enable volume split
curl --location --request POST 'http://localhost:8080/account/merchant_1747841259/business_profile/pro_GUovaynfuaBwH3DUaBbJ/dynamic_routing/set_volume_split?split=100' \
--header 'api-key: dev_9gwSrzjH1Xbs7HMswLgx0Av8upsibfu8wORNxyzpIls3NvT08auKe4RBQlkBgqRl'
  1. Toggle ER config (Call to Decision Engine should be made for ER config creation)
curl --location --request POST 'http://localhost:8080/account/merchant_1747380349/business_profile/pro_28WNE1lOkSX9w3VdEPAN/dynamic_routing/elimination/toggle?enable=dynamic_connector_selection' \
--header 'api-key: dev_d87bY8HlyzBj4YYtGOIK2cj6yZLnPTxEkJN2o3lNJSxck0t3RghiH9zwrOR6Rexs'
{"id":"routing_S5d4ArS1VLlyrnpZ3tTx","profile_id":"pro_28WNE1lOkSX9w3VdEPAN","name":"Elimination based dynamic routing algorithm","kind":"dynamic","description":"","created_at":1747380532,"modified_at":1747380532,"algorithm_for":"payment"}
image
  1. Update ER config
curl --location --request PATCH 'http://localhost:8080/account/merchant_1747380349/business_profile/pro_28WNE1lOkSX9w3VdEPAN/dynamic_routing/elimination/config/routing_S5d4ArS1VLlyrnpZ3tTx' \
--header 'api-key: dev_d87bY8HlyzBj4YYtGOIK2cj6yZLnPTxEkJN2o3lNJSxck0t3RghiH9zwrOR6Rexs' \
--header 'Content-Type: application/json' \
--data '{
    "decision_engine_configs": {
        "threshold": 0.45
    }
}'
{"id":"routing_vOZoBnvZarFhmmLVXElW","profile_id":"pro_28WNE1lOkSX9w3VdEPAN","name":"Elimination based dynamic routing algorithm","kind":"dynamic","description":"","created_at":1747380711,"modified_at":1747380711,"algorithm_for":"payment"}
  1. Activate updated ER config (Call to Decision Engine should be made for ER config updation)
curl --location --request POST 'http://localhost:8080/routing/routing_vOZoBnvZarFhmmLVXElW/activate' \
--header 'api-key: dev_d87bY8HlyzBj4YYtGOIK2cj6yZLnPTxEkJN2o3lNJSxck0t3RghiH9zwrOR6Rexs'
image 8. Disable ER config
curl --location --request POST 'http://localhost:8080/account/merchant_1747380349/business_profile/pro_28WNE1lOkSX9w3VdEPAN/dynamic_routing/elimination/toggle?enable=none' \
--header 'api-key: dev_d87bY8HlyzBj4YYtGOIK2cj6yZLnPTxEkJN2o3lNJSxck0t3RghiH9zwrOR6Rexs'
image
  1. make a payment
curl --location 'http://localhost:8080/payments' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: dev_d87bY8HlyzBj4YYtGOIK2cj6yZLnPTxEkJN2o3lNJSxck0t3RghiH9zwrOR6Rexs' \
--data-raw '{
  "amount": 6540,
  "currency": "USD",
  "confirm": true,
  "capture_method": "automatic",
  "capture_on": "2022-09-10T10:11:12Z",
  "amount_to_capture": 6540,
  "customer_id": "StripeCustomer",
  "email": "guest@example.com",
  "name": "John Doe",
  "phone": "999999999",
  "phone_country_code": "+1",
  "description": "Its my first payment request",
  "authentication_type": "no_three_ds",
  "return_url": "https://google.com",
  "payment_method": "card",
  "payment_method_type": "credit",
  "payment_method_data": {
    "card": {
      "card_number": "4242424242424242",
      "card_exp_month": "10",
      "card_exp_year": "25",
      "card_holder_name": "joseph Doe",
      "card_cvc": "123"
    }
  },
  "billing": {
    "address": {
      "line1": "1467",
      "line2": "Harrison Street",
      "line3": "Harrison Street",
      "city": "San Fransico",
      "state": "California",
      "zip": "94122",
      "country": "US",
      "first_name": "joseph",
      "last_name": "Doe"
    },
    "phone": {
      "number": "8056594427",
      "country_code": "+91"
    }
  },
  "shipping": {
    "address": {
      "line1": "1467",
      "line2": "Harrison Street",
      "line3": "Harrison Street",
      "city": "San Fransico",
      "state": "California",
      "zip": "94122",
      "country": "US",
      "first_name": "joseph",
      "last_name": "Doe"
    },
    "phone": {
      "number": "8056594427",
      "country_code": "+91"
    }
  },
  "statement_descriptor_name": "joseph",
  "statement_descriptor_suffix": "JS",
  "metadata": {
    "udf1": "value1",
    "new_customer": "true",
    "login_date": "2019-09-10T10:11:12Z"
  }
}'
{"payment_id":"pay_WMa1HPuv2m4y1eUa8bJf","merchant_id":"merchant_1747380349","status":"succeeded","amount":6540,"net_amount":6540,"shipping_cost":null,"amount_capturable":0,"amount_received":6540,"connector":"stripe","client_secret":"pay_WMa1HPuv2m4y1eUa8bJf_secret_dLcjgQ2dafDp8Nl1vWZ7","created":"2025-05-16T07:52:09.020Z","currency":"USD","customer_id":"StripeCustomer","customer":{"id":"StripeCustomer","name":"John Doe","email":"guest@example.com","phone":"999999999","phone_country_code":"+1"},"description":"Its my first payment request","refunds":null,"disputes":null,"mandate_id":null,"mandate_data":null,"setup_future_usage":null,"off_session":null,"capture_on":null,"capture_method":"automatic","payment_method":"card","payment_method_data":{"card":{"last4":"4242","card_type":null,"card_network":null,"card_issuer":null,"card_issuing_country":null,"card_isin":"424242","card_extended_bin":null,"card_exp_month":"10","card_exp_year":"25","card_holder_name":"joseph Doe","payment_checks":{"cvc_check":"pass","address_line1_check":"pass","address_postal_code_check":"pass"},"authentication_data":null},"billing":null},"payment_token":null,"shipping":{"address":{"city":"San Fransico","country":"US","line1":"1467","line2":"Harrison Street","line3":"Harrison Street","zip":"94122","state":"California","first_name":"joseph","last_name":"Doe"},"phone":{"number":"8056594427","country_code":"+91"},"email":null},"billing":{"address":{"city":"San Fransico","country":"US","line1":"1467","line2":"Harrison Street","line3":"Harrison Street","zip":"94122","state":"California","first_name":"joseph","last_name":"Doe"},"phone":{"number":"8056594427","country_code":"+91"},"email":null},"order_details":null,"email":"guest@example.com","name":"John Doe","phone":"999999999","return_url":"https://google.com/","authentication_type":"no_three_ds","statement_descriptor_name":"joseph","statement_descriptor_suffix":"JS","next_action":null,"cancellation_reason":null,"error_code":null,"error_message":null,"unified_code":null,"unified_message":null,"payment_experience":null,"payment_method_type":"credit","connector_label":null,"business_country":null,"business_label":"default","business_sub_label":null,"allowed_payment_method_types":null,"ephemeral_key":{"customer_id":"StripeCustomer","created_at":1747381929,"expires":1747385529,"secret":"epk_30f63c59ee2f4ce8b0d4e34a1bdd9119"},"manual_retry_allowed":false,"connector_transaction_id":"pi_3RPJ3tD5R7gDAGff0Jgz3U6C","frm_message":null,"metadata":{"udf1":"value1","login_date":"2019-09-10T10:11:12Z","new_customer":"true"},"connector_metadata":null,"feature_metadata":null,"reference_id":"pi_3RPJ3tD5R7gDAGff0Jgz3U6C","payment_link":null,"profile_id":"pro_28WNE1lOkSX9w3VdEPAN","surcharge_details":null,"attempt_count":1,"merchant_decision":null,"merchant_connector_id":"mca_Zm1nyERaPTww6jSUgtak","incremental_authorization_allowed":null,"authorization_count":null,"incremental_authorizations":null,"external_authentication_details":null,"external_3ds_authentication_attempted":false,"expires_on":"2025-05-16T08:07:09.020Z","fingerprint":null,"browser_info":null,"payment_method_id":null,"payment_method_status":null,"updated":"2025-05-16T07:52:10.486Z","split_payments":null,"frm_metadata":null,"extended_authorization_applied":null,"capture_before":null,"merchant_order_reference_id":null,"order_tax_amount":null,"connector_mandate_id":null,"card_discovery":"manual","force_3ds_challenge":false,"force_3ds_challenge_trigger":false,"issuer_error_code":null,"issuer_error_message":null}
image image

Checklist

  • I formatted the code cargo +nightly fmt --all
  • I addressed lints thrown by cargo clippy
  • I reviewed the submitted code
  • I added unit tests for my changes where possible

@Sarthak1799 Sarthak1799 self-assigned this May 15, 2025
@Sarthak1799 Sarthak1799 requested review from a team as code owners May 15, 2025 12:16
@semanticdiff-com
Copy link

semanticdiff-com bot commented May 15, 2025

Review changes with  SemanticDiff

Changed Files
File Status
  crates/router/src/core/payments/routing.rs  98% smaller
  crates/router/src/core/routing.rs  64% smaller
  crates/router/src/core/payments/routing/utils.rs  13% smaller
  crates/api_models/src/routing.rs  10% smaller
  crates/router/src/core/routing/helpers.rs  6% smaller
  api-reference/openapi_spec.json  0% smaller
  crates/api_models/src/open_router.rs  0% smaller
  crates/openapi/src/openapi.rs  0% smaller
  crates/router/src/core/admin.rs  0% smaller

@Sarthak1799 Sarthak1799 linked an issue May 15, 2025 that may be closed by this pull request
2 tasks
@Sarthak1799 Sarthak1799 added C-feature Category: Feature request or enhancement A-routing Area: Routing labels May 15, 2025
@hyperswitch-bot hyperswitch-bot bot added the M-api-contract-changes Metadata: This PR involves API contract changes label May 16, 2025
@hyperswitch-bot hyperswitch-bot bot requested a review from a team as a code owner May 16, 2025 09:53
jagan-jaya
jagan-jaya previously approved these changes May 21, 2025
Chethan-rao
Chethan-rao previously approved these changes May 21, 2025
likhinbopanna
likhinbopanna previously approved these changes May 21, 2025
@Chethan-rao Chethan-rao requested a review from likhinbopanna May 22, 2025 08:12
@likhinbopanna likhinbopanna enabled auto-merge May 22, 2025 15:07
@likhinbopanna likhinbopanna added this pull request to the merge queue May 22, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks May 22, 2025
@likhinbopanna likhinbopanna added this pull request to the merge queue May 22, 2025
Merged via the queue into main with commit d41f653 May 22, 2025
14 of 20 checks passed
@likhinbopanna likhinbopanna deleted the decision-engine-config branch May 22, 2025 18:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-routing Area: Routing C-feature Category: Feature request or enhancement M-api-contract-changes Metadata: This PR involves API contract changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE] Decision Engine Config API integration

4 participants