api-reference/decision-engine-api-reference/api-reference/guides/configure-routing/routing-advanced-example.mdx
Use algorithm.type = advanced when a merchant needs conditional rule-based routing instead of a fixed connector order. Advanced rules evaluate payment attributes, choose the first matching rule output, and fall back to default_selection when no rule matches.
{
"globals": {},
"default_selection": {
"priority": [
{ "gateway_name": "stripe", "gateway_id": "mca_stripe" }
]
},
"rules": [],
"metadata": {}
}
| Field | Meaning |
|---|---|
globals | Optional reusable value sets referenced by global_ref. |
default_selection | Fallback single, priority, volume_split, or volume_split_priority output. |
rules[].routing_type | Rule output behavior: priority, volume_split, or volume_split_priority. |
rules[].output | Connector output returned when the rule matches. |
rules[].statements[].condition | Conditions inside one statement. All conditions in the same array must match. |
rules[].statements[].nested | Optional nested statements. Parent condition must match and then nested statements are evaluated. |
curl --location "$BASE_URL/routing/create" \
--header "$AUTH_HEADER" \
--header "Content-Type: application/json" \
--data '{
"name": "advanced card routing",
"created_by": "merchant_demo",
"description": "Route Visa card traffic by priority, otherwise fallback to stripe",
"algorithm_for": "payment",
"algorithm": {
"type": "advanced",
"data": {
"globals": {},
"default_selection": {
"priority": [
{ "gateway_name": "stripe", "gateway_id": "mca_stripe" }
]
},
"rules": [
{
"name": "visa_card_rule",
"routing_type": "priority",
"output": {
"priority": [
{ "gateway_name": "adyen", "gateway_id": "mca_adyen" },
{ "gateway_name": "stripe", "gateway_id": "mca_stripe" }
]
},
"statements": [
{
"condition": [
{
"lhs": "payment_method_type",
"comparison": "equal",
"value": { "type": "enum_variant", "value": "CARD" },
"metadata": {}
},
{
"lhs": "card_network",
"comparison": "equal",
"value": { "type": "enum_variant", "value": "Visa" },
"metadata": {}
}
],
"nested": null
}
]
}
],
"metadata": {}
}
}
}'
Use one condition array when all conditions must match.
{
"name": "high_value_netherlands_rule",
"routing_type": "volume_split",
"output": {
"volume_split": [
{
"split": 60,
"output": { "gateway_name": "hdfc", "gateway_id": "mca_hdfc" }
},
{
"split": 40,
"output": { "gateway_name": "instamojo", "gateway_id": "mca_instamojo" }
}
]
},
"statements": [
{
"condition": [
{
"lhs": "amount",
"comparison": "greater_than",
"value": { "type": "number", "value": 100 },
"metadata": {}
},
{
"lhs": "billing_country",
"comparison": "equal",
"value": { "type": "enum_variant", "value": "Netherlands" },
"metadata": {}
}
],
"nested": null
}
]
}
Use multiple statements when any statement can trigger the rule.
{
"name": "card_or_high_value_rule",
"routing_type": "priority",
"output": {
"priority": [
{ "gateway_name": "paytm", "gateway_id": "mca_paytm" },
{ "gateway_name": "adyen", "gateway_id": "mca_adyen" }
]
},
"statements": [
{
"condition": [
{
"lhs": "payment_method_type",
"comparison": "equal",
"value": { "type": "enum_variant", "value": "CARD" },
"metadata": {}
}
],
"nested": null
},
{
"condition": [
{
"lhs": "amount",
"comparison": "greater_than",
"value": { "type": "number", "value": 100 },
"metadata": {}
}
],
"nested": null
}
]
}
Use nested when a parent condition must match and then one nested branch can match.
{
"name": "amount_and_card_network_or_country_rule",
"routing_type": "priority",
"output": {
"priority": [
{ "gateway_name": "rbl", "gateway_id": "mca_rbl" },
{ "gateway_name": "instamojo", "gateway_id": "mca_instamojo" }
]
},
"statements": [
{
"condition": [
{
"lhs": "amount",
"comparison": "greater_than",
"value": { "type": "number", "value": 10 },
"metadata": {}
}
],
"nested": [
{
"condition": [
{
"lhs": "card_network",
"comparison": "equal",
"value": { "type": "enum_variant", "value": "Visa" },
"metadata": {}
}
],
"nested": null
},
{
"condition": [
{
"lhs": "billing_country",
"comparison": "equal",
"value": { "type": "enum_variant", "value": "India" },
"metadata": {}
}
],
"nested": null
}
]
}
]
}
{
"routing_type": "priority",
"output": {
"priority": [
{ "gateway_name": "adyen", "gateway_id": "mca_adyen" },
{ "gateway_name": "stripe", "gateway_id": "mca_stripe" }
]
}
}
{
"routing_type": "volume_split",
"output": {
"volume_split": [
{
"split": 70,
"output": { "gateway_name": "stripe", "gateway_id": "mca_stripe" }
},
{
"split": 30,
"output": { "gateway_name": "adyen", "gateway_id": "mca_adyen" }
}
]
}
}
Use volume_split_priority when each split should return a priority list rather than a single connector.
{
"routing_type": "volume_split_priority",
"output": {
"volume_split_priority": [
{
"split": 60,
"output": [
{ "gateway_name": "stripe", "gateway_id": "mca_stripe" },
{ "gateway_name": "adyen", "gateway_id": "mca_adyen" }
]
},
{
"split": 40,
"output": [
{ "gateway_name": "checkout", "gateway_id": "mca_checkout" },
{ "gateway_name": "stripe", "gateway_id": "mca_stripe" }
]
}
]
}
}
{
"lhs": "card_network",
"comparison": "equal",
"value": {
"type": "enum_variant_array",
"value": ["Visa", "Mastercard"]
},
"metadata": {}
}
{
"lhs": "amount",
"comparison": "equal",
"value": {
"type": "number_array",
"value": [1000, 2000, 5000]
},
"metadata": {}
}
{
"lhs": "amount",
"comparison": "equal",
"value": {
"type": "number_comparison_array",
"value": [
{ "comparison_type": "greater_than", "number": 1000 },
{ "comparison_type": "less_than_equal", "number": 5000 }
]
},
"metadata": {}
}
statements; top-level single, priority, and volume_split algorithms do not.condition array behave like AND.nested allows a parent condition plus nested branch matching.volume_split percentages should add up to 100.