Checkout rules (Beta)
Let an app apply a wholesale discount or reject an order at checkout with a declarative JSON rule that Nimlio evaluates for you.
Rolling out gradually; it may not be active for your business yet
Beta. The contract below may still change before general availability. It requires an installed OAuth app with a checkout rules scope.
What rules can do
A checkout rule is a small JSON document that your app registers on a business. Nimlio interprets it at checkout; no code of yours runs in the buyer's request. There are two kinds:
- Discount rules reduce the order when a condition matches, for example 10% when the buyer orders 12 or more units.
- Validation rules reject the order with a message in English and Spanish, for example when the shipping department is outside your delivery area.
Rules are declarative: no regular expressions, arithmetic or loops, so every evaluation finishes within fixed limits.
Manage rules from your app
Call the Admin API with a token that has the scope checkout_rules:read (list and read) or checkout_rules:write (create, change and delete). Send the rule document inside the body: POST takes { "document": … }, and PATCH takes { "document": …, "revision": … } with the revision of the rule you last read.
| Method and path | Scope |
|---|---|
GET /api/v1/admin/checkout-rules | checkout_rules:read |
POST /api/v1/admin/checkout-rules | checkout_rules:write |
GET /api/v1/admin/checkout-rules/:ruleId | checkout_rules:read |
PATCH /api/v1/admin/checkout-rules/:ruleId | checkout_rules:write |
DELETE /api/v1/admin/checkout-rules/:ruleId | checkout_rules:write |
A rule you create is disabled until the merchant enables it in Dashboard → Integrations (Checkout rules card). Updating a rule from your app keeps the merchant's enabled setting. A rule only runs while your app is installed on the business, and stops when the merchant uninstalls it.
Discount rule
A discount has a when condition and an effect: either percentage (percent from 1 to 100) or fixed (amount, a positive integer in COP centavos). Example: 10% off the whole order when it has 12 or more units.
{
"kind": "discount",
"name": "Wholesale 10%",
"when": {
"op": "gte",
"args": [
{
"fact": "quantity"
},
12
]
},
"effect": {
"type": "percentage",
"percent": 10
},
"combinesWithOrderDiscounts": false
}- At most one app discount applies to an order: the first enabled rule that matches, in the order the merchant arranged.
- It is an order-level discount. By default (
combinesWithOrderDiscounts: false) it is skipped if Nimlio's own discounts already applied an order-level discount; it does combine with product and shipping discounts. SetcombinesWithOrderDiscountstotrueto allow stacking. - It is calculated on the merchandise subtotal after Nimlio's product and order discounts, never goes below zero or above that amount, and never touches shipping.
- With no enabled rules, the order total is exactly what it was before.
Validation rule
A validation has rejectWhen: if the condition is true, the order is blocked and the buyer sees message in their language (en and es, plain text up to 200 characters each). Validations run after discounts, on the final totals, in the merchant's order; the first rejection stops the evaluation.
{
"kind": "validation",
"name": "Bogotá and Cundinamarca only",
"rejectWhen": {
"op": "not",
"arg": {
"op": "in",
"arg": {
"fact": "shipping.departmentCode"
},
"values": [
"11",
"25"
]
}
},
"message": {
"en": "We only deliver in Bogotá and Cundinamarca.",
"es": "Solo entregamos en Bogotá y Cundinamarca."
}
}{
"kind": "validation",
"name": "Phone has 10 characters or more",
"rejectWhen": {
"op": "not",
"arg": {
"op": "gte",
"args": [
{
"op": "len",
"arg": {
"fact": "customer.phone"
}
},
10
]
}
},
"message": {
"en": "Enter a phone number with at least 10 digits.",
"es": "Escribe un teléfono con al menos 10 dígitos."
}
}Conditions
Conditions are built from literals, facts and operations. Literals are integers (no decimals), strings, booleans and null. A fact is { "fact": "<path>" }; a missing fact is null.
| Operation | Shape | Notes |
|---|---|---|
and, or | { "op": "and", "args": [e, …] } | 1 to 16 arguments |
not | { "op": "not", "arg": e } | |
eq, neq | { "op": "eq", "args": [a, b] } | |
lt, lte, gt, gte | { "op": "gt", "args": [a, b] } | Integers only; a null operand gives false |
in | { "op": "in", "arg": e, "values": [literal, …] } | Up to 100 values |
len | { "op": "len", "arg": e } | String length; null is 0 |
digits | { "op": "digits", "arg": e } | True for a non-empty string of 0-9 |
startsWith | { "op": "startsWith", "arg": e, "prefix": "…" } | |
present | { "op": "present", "arg": e } | True for a non-blank string |
anyLine, allLines | { "op": "anyLine", "where": e } | Cannot be nested; line.* facts are visible inside |
Facts
| Fact | Meaning |
|---|---|
subtotal, discountedSubtotal, shippingAmount | Order amounts in COP centavos |
quantity, lineCount | Sum of line quantities; number of lines |
shipping.departmentCode, shipping.municipalityCode | DANE codes of the shipping department (e.g. "11" for Bogotá) and municipality (e.g. "11001") |
customer.email, customer.phone | Buyer contact details |
line.productId, line.variantId, line.quantity, line.unitAmount, line.lineTotal | Only inside anyLine or allLines |
Every amount, in facts and in fixed effects, is an integer number of COP centavos. 45.000 COP is 4500000. Never send decimals.
Limits
| Limit | Value |
|---|---|
| Document size | 8192 bytes |
| Nodes per document | 256 |
| Nesting depth | 12 |
| String length | 200 characters |
Values in an in list | 100 |
| Rules per business | 20 |
| Steps per rule | 2000 (each node counts one; anyLine and allLines count per line) |
| Time per evaluation | 20 ms in total |
When a rule fails
- Validation rule that errors or exceeds a limit: checkout is blocked (fail closed) with a generic message and the reason
checkout_rule_unavailable. - Discount rule that errors or exceeds a limit: no app discount is applied (fail open) and checkout continues.