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

Open
wants to merge 38 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
c003cfe
feat: Integrate contract routing
Sarthak1799 Dec 3, 2024
7d1cbe3
Merge branch 'main' of github.com:juspay/hyperswitch into contracts-d…
Sarthak1799 Dec 3, 2024
354314a
chore: Fixed some implementaions
Sarthak1799 Dec 3, 2024
df8bab3
feat: Implemented cache related stuff
Sarthak1799 Dec 4, 2024
fb830b8
fix: Fixed errors
Sarthak1799 Dec 4, 2024
063d978
feat: Added new endpoint for contracts
Sarthak1799 Dec 5, 2024
a0b334c
feat: Implemented config routes for contracts
Sarthak1799 Dec 5, 2024
1bf3f9b
Merge branch 'main' of github.com:juspay/hyperswitch into contracts-d…
Sarthak1799 Dec 5, 2024
535532c
chore: run formatter
hyperswitch-bot[bot] Dec 5, 2024
f5454d6
fix: Fixed errors
Sarthak1799 Dec 5, 2024
025f70c
refactor: Refactored routing callers into single function
Sarthak1799 Dec 7, 2024
e5ad76b
chore: run formatter
hyperswitch-bot[bot] Dec 7, 2024
c3cf07a
fix: Fixed clippy errors
Sarthak1799 Dec 8, 2024
e17beee
chore: run formatter
hyperswitch-bot[bot] Dec 8, 2024
59e573c
refactor: Changed order of contract functions
Sarthak1799 Dec 9, 2024
3c471f9
fix: Fixed metrics
Sarthak1799 Dec 12, 2024
0a5c5e1
fix: Fixed clippy errors
Sarthak1799 Dec 12, 2024
198a308
chore: run formatter
hyperswitch-bot[bot] Dec 12, 2024
5ec8b3f
fix: Fixed errors
Sarthak1799 Dec 12, 2024
f9f0e27
Merge branch 'main' of github.com:juspay/hyperswitch into contracts-d…
Sarthak1799 Dec 13, 2024
17044b1
chore: run formatter
hyperswitch-bot[bot] Dec 13, 2024
584db45
chore: Refactored a bit
Sarthak1799 Dec 16, 2024
a1732d4
chore: run formatter
hyperswitch-bot[bot] Dec 16, 2024
9630a45
chore: Resolved comments
Sarthak1799 Dec 17, 2024
6a01879
Merge branch 'main' of github.com:juspay/hyperswitch into contracts-d…
Sarthak1799 Dec 18, 2024
01907d5
chore: Resolved comments
Sarthak1799 Dec 18, 2024
cbc9478
fix: Fixed errors
Sarthak1799 Dec 18, 2024
f4dec0b
chore: Resolved comments
Sarthak1799 Dec 19, 2024
130ce8e
chore: Resolved comments
Sarthak1799 Dec 20, 2024
7a03ea2
Merge branch 'main' of github.com:juspay/hyperswitch into contracts-d…
Sarthak1799 Dec 23, 2024
6241147
chore: Resolved comments
Sarthak1799 Dec 23, 2024
da5c476
chore: run formatter
hyperswitch-bot[bot] Dec 23, 2024
acdf379
fix: Fixed errors
Sarthak1799 Dec 23, 2024
a646967
refactor: Added db call for stats
Sarthak1799 Dec 24, 2024
c031d24
fix: Resolved comments
Sarthak1799 Dec 24, 2024
b45a01f
chore: run formatter
hyperswitch-bot[bot] Dec 24, 2024
6eb3a8d
chore: Resolved comments
Sarthak1799 Dec 26, 2024
0f4535b
chore: run formatter
hyperswitch-bot[bot] Dec 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ crates/router/src/core/routing @juspay/hyperswitch-routing
crates/router/src/core/routing.rs @juspay/hyperswitch-routing
crates/router/src/core/payments/routing @juspay/hyperswitch-routing
crates/router/src/core/payments/routing.rs @juspay/hyperswitch-routing
crates/external_services/src/grpc_client/dynamic_routing.rs @juspay/hyperswitch-routing
crates/external_services/src/grpc_client/dynamic_routing/ @juspay/hyperswitch-routing
crates/external_services/src/grpc_client/health_check_client.rs @juspay/hyperswitch-routing

crates/api_models/src/payment_methods.rs @juspay/hyperswitch-routing
crates/router/src/core/payment_methods.rs @juspay/hyperswitch-routing
Expand Down
247 changes: 245 additions & 2 deletions api-reference/openapi_spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -4080,7 +4080,7 @@
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/DynamicRoutingFeatures"
"$ref": "#/components/schemas/SuccessBasedRoutingConfig"
}
}
},
Expand Down Expand Up @@ -4227,7 +4227,7 @@
{
"name": "enable",
"in": "query",
"description": "Feature to enable for success based routing",
"description": "Feature to enable for elimination based routing",
"required": true,
"schema": {
"$ref": "#/components/schemas/DynamicRoutingFeatures"
Expand Down Expand Up @@ -4271,6 +4271,174 @@
]
}
},
"/account/:account_id/business_profile/:profile_id/dynamic_routing/contracts/toggle": {
"post": {
"tags": [
"Routing"
],
"summary": "Routing - Toggle Contract routing for profile",
"description": "Create a Contract based dynamic routing algorithm",
"operationId": "Toggle contract routing algorithm",
"parameters": [
{
"name": "account_id",
"in": "path",
"description": "Merchant id",
"required": true,
"schema": {
"type": "string"
}
},
{
"name": "profile_id",
"in": "path",
"description": "Profile id under which Dynamic routing needs to be toggled",
"required": true,
"schema": {
"type": "string"
}
},
{
"name": "enable",
"in": "query",
"description": "Feature to enable for contract based routing",
"required": true,
"schema": {
"$ref": "#/components/schemas/DynamicRoutingFeatures"
}
}
],
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ContractBasedRoutingConfig"
}
}
},
"required": true
},
"responses": {
"200": {
"description": "Routing Algorithm created",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/RoutingDictionaryRecord"
}
}
}
},
"400": {
"description": "Request body is malformed"
},
"403": {
"description": "Forbidden"
},
"404": {
"description": "Resource missing"
},
"422": {
"description": "Unprocessable request"
},
"500": {
"description": "Internal server error"
}
},
"security": [
{
"api_key": []
},
{
"jwt_key": []
}
]
}
},
"/account/{account_id}/business_profile/{profile_id}/dynamic_routing/contracts/config/{algorithm_id}": {
"patch": {
"tags": [
"Routing"
],
"summary": "Routing - Update contract based dynamic routing config for profile",
"description": "Update contract based dynamic routing algorithm",
"operationId": "Update contract based dynamic routing configs",
"parameters": [
{
"name": "account_id",
"in": "path",
"description": "Merchant id",
"required": true,
"schema": {
"type": "string"
}
},
{
"name": "profile_id",
"in": "path",
"description": "Profile id under which Dynamic routing needs to be toggled",
"required": true,
"schema": {
"type": "string"
}
},
{
"name": "algorithm_id",
"in": "path",
"description": "Contract based routing algorithm id which was last activated to update the config",
"required": true,
"schema": {
"type": "string"
}
}
],
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ContractBasedRoutingConfig"
}
}
},
"required": true
},
"responses": {
"200": {
"description": "Routing Algorithm updated",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/RoutingDictionaryRecord"
}
}
}
},
"400": {
"description": "Update body is malformed"
},
"403": {
"description": "Forbidden"
},
"404": {
"description": "Resource missing"
},
"422": {
"description": "Unprocessable request"
},
"500": {
"description": "Internal server error"
}
},
"security": [
{
"api_key": []
},
{
"jwt_key": []
}
]
}
},
"/blocklist": {
"delete": {
"tags": [
Expand Down Expand Up @@ -9465,6 +9633,54 @@
},
"additionalProperties": false
},
"ContractBasedRoutingConfig": {
"type": "object",
"properties": {
"config": {
"allOf": [
{
"$ref": "#/components/schemas/ContractBasedRoutingConfigBody"
}
],
"nullable": true
},
"label_info": {
"type": "array",
"items": {
"$ref": "#/components/schemas/LabelInformation"
},
"nullable": true
}
}
},
"ContractBasedRoutingConfigBody": {
"type": "object",
"properties": {
"constants": {
"type": "array",
"items": {
"type": "number",
"format": "double"
},
"nullable": true
},
"time_scale": {
"allOf": [
{
"$ref": "#/components/schemas/ContractBasedTimeScale"
}
],
"nullable": true
}
}
},
"ContractBasedTimeScale": {
"type": "string",
"enum": [
"day",
"month"
]
},
"CountryAlpha2": {
"type": "string",
"enum": [
Expand Down Expand Up @@ -12775,6 +12991,33 @@
}
}
},
"LabelInformation": {
"type": "object",
"required": [
"label",
"target_count",
"target_time",
"mca_id"
],
"properties": {
"label": {
"type": "string"
},
"target_count": {
"type": "integer",
"format": "int64",
"minimum": 0
},
"target_time": {
"type": "integer",
"format": "int64",
"minimum": 0
},
"mca_id": {
"type": "string"
}
}
},
"LinkedRoutingConfigRetrieveResponse": {
"oneOf": [
{
Expand Down
25 changes: 19 additions & 6 deletions crates/api_models/src/events/routing.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use common_utils::events::{ApiEventMetric, ApiEventsType};

use crate::routing::{
LinkedRoutingConfigRetrieveResponse, MerchantRoutingAlgorithm, ProfileDefaultRoutingConfig,
RoutingAlgorithmId, RoutingConfigRequest, RoutingDictionaryRecord, RoutingKind,
RoutingLinkWrapper, RoutingPayloadWrapper, RoutingRetrieveLinkQuery,
ContractBasedRoutingPayloadWrapper, ContractBasedRoutingSetupPayloadWrapper,
DynamicRoutingUpdateConfigQuery, LinkedRoutingConfigRetrieveResponse, MerchantRoutingAlgorithm,
ProfileDefaultRoutingConfig, RoutingAlgorithmId, RoutingConfigRequest, RoutingDictionaryRecord,
RoutingKind, RoutingLinkWrapper, RoutingPayloadWrapper, RoutingRetrieveLinkQuery,
RoutingRetrieveLinkQueryWrapper, RoutingRetrieveQuery, RoutingVolumeSplitWrapper,
SuccessBasedRoutingConfig, SuccessBasedRoutingPayloadWrapper,
SuccessBasedRoutingUpdateConfigQuery, ToggleDynamicRoutingQuery, ToggleDynamicRoutingWrapper,
SuccessBasedRoutingConfig, SuccessBasedRoutingPayloadWrapper, ToggleDynamicRoutingQuery,
ToggleDynamicRoutingWrapper,
};

impl ApiEventMetric for RoutingKind {
Expand Down Expand Up @@ -97,13 +98,25 @@ impl ApiEventMetric for SuccessBasedRoutingPayloadWrapper {
}
}

impl ApiEventMetric for ContractBasedRoutingPayloadWrapper {
fn get_api_event_type(&self) -> Option<ApiEventsType> {
Some(ApiEventsType::Routing)
}
}

impl ApiEventMetric for ContractBasedRoutingSetupPayloadWrapper {
fn get_api_event_type(&self) -> Option<ApiEventsType> {
Some(ApiEventsType::Routing)
}
}

impl ApiEventMetric for ToggleDynamicRoutingWrapper {
fn get_api_event_type(&self) -> Option<ApiEventsType> {
Some(ApiEventsType::Routing)
}
}

impl ApiEventMetric for SuccessBasedRoutingUpdateConfigQuery {
impl ApiEventMetric for DynamicRoutingUpdateConfigQuery {
fn get_api_event_type(&self) -> Option<ApiEventsType> {
Some(ApiEventsType::Routing)
}
Expand Down
Loading
Loading