Skip to content
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

feat(routing): Contract based routing integration #6761

Merged
merged 58 commits into from
Feb 6, 2025

Conversation

Sarthak1799
Copy link
Contributor

@Sarthak1799 Sarthak1799 commented Dec 5, 2024

Type of Change

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

Description

  • Built an interface for Contract based routing
  • Integrated Contract based routing with hyperswitch
  • Built new APIs for contract routing config setup
  • Refactored some existing dynamic routing code

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. Enable Contract routing config
curl --location --request POST 'http://localhost:8080/account/sarthak2/business_profile/pro_YozTgS8HebvBlk0UaeWW/dynamic_routing/contracts/toggle?enable=dynamic_connector_selection' \
--header 'api-key: dev_1aD8YuFd6Ovanf3oOtAYobqI6qw4ZBRSfw6BgYbifWHpaopkisBtm8obNXkFbVJn' \
--header 'Content-Type: application/json' \
--data-raw '{
    "config": {
        "constants": [0.7,0.35],
        "time_scale": "day"
    },
    "label_info": [{
        "label": "stripe",
        "target_count": 10000,
        "incremental_count": 0,
        "target_time": 1780486655,
        "mca_id": "mca_5Mk0Qcum2tnbmKoyqeuL"
    }]
}'

Response -

{
    "id": "routing_FlQ49V71J8ZCXEwPzFy9",
    "profile_id": "pro_YozTgS8HebvBlk0UaeWW",
    "name": "Contract based dynamic routing algorithm",
    "kind": "dynamic",
    "description": "",
    "created_at": 1734009361,
    "modified_at": 1734009361,
    "algorithm_for": "payment"
}
  1. Set Volume split for dynamic routing
curl --location --request POST 'http://localhost:8080/account/sarthak2/business_profile/pro_YozTgS8HebvBlk0UaeWW/dynamic_routing/set_volume_split?split=80' \
--header 'api-key: dev_1aD8YuFd6Ovanf3oOtAYobqI6qw4ZBRSfw6BgYbifWHpaopkisBtm8obNXkFbVJn'
  1. Create a Payment
    Metrics Population post payment -
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 Dec 5, 2024
@Sarthak1799 Sarthak1799 requested review from a team as code owners December 5, 2024 20:19
Copy link

semanticdiff-com bot commented Dec 5, 2024

@Sarthak1799 Sarthak1799 added A-core Area: Core flows A-routing Area: Routing labels Dec 5, 2024
@Sarthak1799 Sarthak1799 linked an issue Dec 12, 2024 that may be closed by this pull request
2 tasks
Chethan-rao
Chethan-rao previously approved these changes Jan 21, 2025
Copy link
Member

@NishantJoshi00 NishantJoshi00 left a comment

Choose a reason for hiding this comment

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

Looks good, some questions:

  1. Is this enabled by default?
  2. Have you tested if this works for a contract?
  3. Where are the state for this being stored?
  4. Where is the flow this is being called?
  5. Are any interactions with dynamic routing service in the critical path (if so, how do we handle network failures)
  6. I was able to see some caching changes, will this affect the state management for managing contract.

I think its imperative to follow micro PR model to avoid such confusions;

  1. it becomes difficult to follow the code changes.
  2. Such massive changes can hide bugs which are difficult to find due to its sheer size.

@Sarthak1799
Copy link
Contributor Author

  • We have to enable contract based routing using setup APIs introduced in this PR
  • have tested the flow locally
  • The actual config is stored in routing_algorithm with it's ref stored in profile, like all other DR algorithms
  • Similar to other routing types, this will be called in the payment flow, if the contract based algo is enabled.
  • In case of Dynamic routing failure, the list of eligible of connectors are defaulted to the list from static routing
  • The caching changes here are to make the caching code generic to all categories of Dynamic routing (SR, ER, Contracts) and making use of specific functions from redis interface (like get_or_populate_in_memory)
    cc: @Chethan-rao

Agreed on the micro PR model @NishantJoshi00, had thought about breaking up in several PRs but much of the reviews were already completed at the time.

NishantJoshi00
NishantJoshi00 previously approved these changes Jan 28, 2025
tsdk02
tsdk02 previously approved these changes Jan 28, 2025
@likhinbopanna likhinbopanna added this pull request to the merge queue Feb 5, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Feb 5, 2025
@likhinbopanna likhinbopanna added this pull request to the merge queue Feb 6, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Feb 6, 2025
@likhinbopanna likhinbopanna added this pull request to the merge queue Feb 6, 2025
Merged via the queue into main with commit 60ddddf Feb 6, 2025
17 of 20 checks passed
@likhinbopanna likhinbopanna deleted the contracts-dr-router-integration branch February 6, 2025 14:35
pixincreate added a commit that referenced this pull request Feb 7, 2025
…unt-configurable

* 'main' of github.com:juspay/hyperswitch: (37 commits)
  refactor(router): add display_name field to connector feature api  (#7121)
  ci(cypress): Add Tests for Customer Deletion and Psync flows (#7158)
  feat(connector): [DataTrans] ADD 3DS Flow (#6026)
  chore(version): 2025.02.07.0
  chore(connectors): [fiuu] update pm_filters for apple pay and google pay (#7182)
  feat(router): add `organization_id` in authentication table and add it in authentication events (#7168)
  fix(dashboard_metadata): mask `poc_email` and `data_value` for DashboardMetadata (#7130)
  feat(core): Add support for v2 payments get intent using merchant reference id (#7123)
  refactor(customer): return redacted customer instead of error (#7122)
  fix(connector): handle unexpected error response from bluesnap connector (#7120)
  feat(routing): Contract based routing integration  (#6761)
  refactor(dynamic_fields): dynamic fields for Adyen and Stripe, renaming klarnaCheckout, WASM for KlarnaCheckout (#7015)
  feat(connector): [COINGATE] Add Template PR  (#7052)
  chore(roles): remove redundant variant from PermissionGroup (#6985)
  refactor(router): store `network_transaction_id` for `off_session` payments irrespective of the `is_connector_agnostic_mit_enabled` config (#7083)
  chore(connector): [Fiuu] log keys in the PSync response (#7189)
  ci(cypress): fix nmi and paypal (#7173)
  chore(version): 2025.02.06.0
  chore(postman): update Postman collection files
  feat(connector): [Deutschebank] Add Access Token Error struct (#7127)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-core Area: Core flows A-routing Area: Routing 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] Contract Routing Integration
6 participants