Several till rules in one app, with the retailer's own settings (till guard rules) — the recipe
A retailer rarely wants one rule at the till. It wants a handful: a manager for a large sale or a price below an item's lowest, no line at a placeholder price, a most-per-line quantity, a most lines per sale, a beep on a flagged item. This recipe puts them in one app: a check before payment for the rules at Pay, a capture on scan for the rule at the scan, and one settings record the retailer edits in Desk, which your service reads. It is for an iVendNext Partner, or the CitiXsys Consulting Team.
Next: the sample, S23 · Till guard rulesAll recipes
In the App library: Till guard rules
Reference implementation: samples/s23_till_guard/ — Till guard rules.
When to use it. Your rules need numbers or choices that differ from retailer to retailer, and one service answers many retailers. For one rule with fixed settings, the check alone is enough (recipe); for a value captured at the scan, the capture (recipe).
Steps
-
Declare the two services and the settings in your manifest (
samples/s23_till_guard/manifest.json):- a record type
<PREFIX> Settings(an ordinary record type; the service reads the record namedDefault). Give System Manager the rights to edit it, and your integration role read only. The install makes that role when iVendNext lacks it: the sample's isPP TGR Integration; - a Check field on Item (Confirm at the till when scanned), and the capture's filter on it:
"settings": {"event": "scan", "item_field": "<prefix>_confirm_at_scan"}. Online, the server reads the tick at each scan and calls you only for a ticked item; offline you are not called, and the till applies your down answer to the items ticked at its start of day (at most 2,000); - a
checksubscription and acapturesubscription, each at its own address; - a feed registration (
registered_applications), one per app, with no user named: the install makes your app's own user,<app>@integration.invalid, and names it, and the retailer's site hands that user's key to your hosted service after the install or an update (Connect again only if the site could not reach the app, or a key was lost or changed); - a help address on the settings record type (a
documentationproperty setter), so Desk's help on the record opens your page at its settings.
- a record type
-
Choose what happens when your service is down. Till guard rules declares
allow_and_flagfor both: an outage never stops a retailer selling, and each sale is flagged on Sales to review. A retailer that wants a rule to hold in an outage changes its subscription torefuse(the check's three down answers are in the check recipe). -
Check every call with its own route's secret. The install makes one secret per service,
<app>:sub:<key>. The check's address accepts only the check's secret, the scan's only the scan's (service/app.py,ROUTES). -
Read the retailer's settings with your integration user's key, and keep them a minute.
GET /api/resource/<PREFIX> Settings/Default. No record yet: every rule off. iVendNext cannot be read: use the last rules you read for a short while (S23: ten minutes, kept by each running copy of the service, so a copy that has just started has none), then answer 503 so the till applies your down answer. Never follow a redirect with the key. -
Answer. At Pay, the first refusal wins (
refuse+reason); then a line below its lowest price, or a large sale, getsask(a yes/no; S23's default, it needs nothing more) orapprove(a manager who is not the cashier signs in). At the scan,confirm+question: the till beeps and asks. What a sale or a return takes back is never judged; what a return sells (an exchange rung without its sale: lines with a positive quantity) is judged by the line rules, and the large-sale rule reads the total the customer pays (on an exchange, net of what it takes back), so an exchange cannot dodge it. On a return the till's headline is This refund can't go ahead. Every sentence is plain text of 1 to 140 characters.Rule Answer a line priced above 0 and at or below the retailer's placeholder price {"verdict": "refuse", "reason": "Line 2: Blue pen is priced 0.01 AED. Correct its price before the sale is paid."}a line holding more than the retailer's most (line by line: a promotion may split one item across lines) {"verdict": "refuse", "reason": "Line 1: 60 of Water, 24 pack. The most on one line is 50: take 10 off."}more lines sold than the retailer's most lines on one sale {"verdict": "refuse", "reason": "This sale has 41 lines. The most on one sale is 40. Ring the rest as a second sale."}a line priced above 0 and below its lowest price, in the retailer's price list of lowest prices (the line's own unit; approvechosen){"verdict": "approve", "reason": "Line 2: Cement, 50 kg is 18.00 SAR, below its lowest price of 20.00 SAR. It needs a manager's approval."}a sale at or above the approval amount (the retailer's default, ask){"verdict": "ask", "question": "This sale is 5,000.00 AED or more. Has a manager agreed to it?"}the same, when the retailer chose approve{"verdict": "approve", "reason": "Sales of 5,000.00 AED or more need a manager's approval."}a flagged item scanned {"verdict": "confirm", "question": "Blue pen: Check this item before it goes on the sale. Add it?"} -
Tell iVendNext what to do (the sample's README, and your card's setup steps): the services are on from the install, so the customer makes the
Defaultrecord and ticks the items; the app's role (the install added it, and the app's own user holds it) has its reads from the install and the manifest'srole_rights(Item Price, Batch, Warehouse and POS Profile in S23), so the administrator gives none. Forapprove: first give each manager May Approve a Partner's Check on their Retail Permission and write access to Retail Override Request (the check refuses the next tick until someone other than the cashier can approve), then tick May ask for a manager's approval on the check. Without the tick, anapproveanswer cannot be used and the till applies your down answer. -
Test it. The sample's tests: each rule, each route's secret, the record read and kept, one retailer and many, every answer against the contracts;
canaries.pybreaks each guarded rule and expects its test to fail. Then press Pay and scan on a sandbox.
Settings
The retailer's record Default of <PREFIX> Settings, each rule off until set (0 or blank = off): a line priced at or below this is refused (a placeholder price such as 0.01; a free line is never refused), lowest prices (a price list of the retailer's, one Item Price row per item and unit, in the sale's currency; the service reads those rows for the basket's items after the refusals, so a list that cannot be read never stops a refusal; the integration role's read on Item Price is in the manifest's role_rights), most of one item on a line, most lines on one sale, sales of this amount or more need a manager, question to ask at Pay for a walk-in sale (the shop's own words: at the check, when the customer is the store's walk-in, the store's cash customer or the till's default customer, the service answers ask with it; the first button goes on to payment and the second back to the basket. From POS build 2.1.0.749, Yes button and No button (such as Pay as walk-in and Add club number) ride the ask as buttons, and the question can say where the member goes: Walk-in sale. Pay without a club number? To add one, go back and search their phone or name in Scan or search. With either blank the till shows Yes / No, so the question spells the answers: Walk-in sale. Yes: pay as walk-in. No: go back and add the member.; a named customer is never asked, nor is a return or an exchange; a walk-in sale that needs a manager, a large sale or a line below its lowest price, gets that question instead, one answer for each press of Pay; if the walk-in cannot be read the sale goes on, because it is a reminder and not a gate), how a sale needing a manager is checked (ask or approve, for a large sale and a line below its lowest price) and the question on a flagged item. Amounts are one number for every currency, read in the sale's own currency. A change reaches the service within a minute.




What iVendNext needs from you
| You give | iVendNext checks |
|---|---|
| an HTTPS address its server trusts, per service | the address is consented; a private address is refused on a customer's site |
| a settings record type and a field, by manifest | the installer makes them and removes them at uninstall |
| a signature check per route | — (yours to do) |
| an answer within the timeout (3 s at Pay, 1.5 s at the scan) | your declared down answer applies otherwise |
Technical notes
- Configure before you code a price rule. iVendNext already refuses a price below cost (Selling Settings, Validate Selling Price), holds a cashier's price change inside a share of the list price unless a manager approves (Retail Permission, price override lower and upper limit), and caps a line's discount (the item's Max Discount (%)). A lowest price per item and unit is what those leave open.
- Offline, the till does not call you: each service's declared down answer applies, and the sale is flagged when it syncs.
- Hosting: the service is the app template's shape, so it serves many retailers through the template's handshake (Publish your app); each retailer's site hands over the two secrets when it connects after the install, and its integration user's key, which the site hands over after the install or an update. It only answers presses, so on CitiXsys hosting it runs as a function, paid per call (
app.json"runs": "function"). Until a retailer's user key arrives the service answers 503, so your down answer applies.
Needs this serves
- A discount above a set limit needs a manager's approval — Ready, with limits (2)
- A manager must approve a sale over a set amount — Ready, with limits (2)
- No line at a placeholder price such as 0.01 — Ready, with limits (1)
- No more than 50 of one item on a line — Ready, with limits (1)
- Selling below the minimum price needs a manager's approval — Ready, with limits (2)