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.

Availability

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 pathScope
GET /api/v1/admin/checkout-rulescheckout_rules:read
POST /api/v1/admin/checkout-rulescheckout_rules:write
GET /api/v1/admin/checkout-rules/:ruleIdcheckout_rules:read
PATCH /api/v1/admin/checkout-rules/:ruleIdcheckout_rules:write
DELETE /api/v1/admin/checkout-rules/:ruleIdcheckout_rules:write
New rules start disabled

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.

Wholesale discount
{
"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. Set combinesWithOrderDiscounts to true to 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.

Reject shipping outside a list of departments (DANE codes)
{
"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."
}
}
Require a phone number of at least 10 digits
{
"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.

OperationShapeNotes
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

FactMeaning
subtotal, discountedSubtotal, shippingAmountOrder amounts in COP centavos
quantity, lineCountSum of line quantities; number of lines
shipping.departmentCode, shipping.municipalityCodeDANE codes of the shipping department (e.g. "11" for Bogotá) and municipality (e.g. "11001")
customer.email, customer.phoneBuyer contact details
line.productId, line.variantId, line.quantity, line.unitAmount, line.lineTotalOnly inside anyLine or allLines
Money is integer COP centavos

Every amount, in facts and in fixed effects, is an integer number of COP centavos. 45.000 COP is 4500000. Never send decimals.

Limits

LimitValue
Document size8192 bytes
Nodes per document256
Nesting depth12
String length200 characters
Values in an in list100
Rules per business20
Steps per rule2000 (each node counts one; anyLine and allLines count per line)
Time per evaluation20 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.