Discussions
How to Build a POS Receipt and Refund Approval Flow With Agilit-e Numbering, Templates and BPM
In Agilit-e, a point of sale can get a unique receipt number from the Numbering module (POST /numbering/generate), render the customer receipt from a Templates profile (POST /templates/execute), produce a PDF copy with the generatePDF utility, and send every refund through a BPM process (/bpm/registerBPMRecord and /bpm/execute) so a manager approves it before money goes back. Each call needs only the api-key header plus the profile or process key, so the whole flow fits in about 100 lines of Node.js.
I have seen a few questions about using Agilit-e for retail and hospitality back-office work, so here is a pattern that maps neatly onto the platform's modules. Happy to hear how others have set this up.
Why use Agilit-e for receipts and refunds?
Two things go wrong in most POS setups:
Receipt numbers clash. Each till keeps its own counter, two tills issue the same number, and the accountant spends a day untangling it.
Refunds have no trail. A cashier refunds a sale, nobody approves it, and weeks later nobody can say who refunded what or why.
Agilit-e already has a module for each half of the problem. Numbering hands out unique numbers from one central counter. BPM moves a record through steps, assigns each step to a role and keeps a history of who chose which option. Templates and the PDF utility take care of the document the customer sees.
What does the flow look like?
Step Agilit-e module Endpoint
Get a receipt number Numbering POST /numbering/generate
Render the receipt (email or print) Templates POST /templates/execute
Keep a PDF copy Utility Services POST /utils/generatePDF
Cashier requests a refund Numbering + BPM /numbering/generate, then GET /bpm/registerBPMRecord
Cashier submits it for approval BPM POST /bpm/execute with option submit
Manager approves or rejects BPM + Roles POST /bpm/execute with option approve or reject
What do you set up in the Admin Portal first?
Create these four profiles in the Admin Portal. The keys below are examples, so use your own:
Numbering profile pos-receipt: the receipt counter. A prefix such as {{param1}}- lets each store code appear in front of the number, because the generate call passes param1 and param2 to the profile's Mustache tags.
Numbering profile pos-refund: a separate counter for refund references, so refunds never share a sequence with sales.
Templates profile pos-receipt-html: the receipt layout, with placeholders for the receipt number (param1) and the line items (param2).
BPM profile pos-refund-approval: three steps, refund_requested (role: Cashier, option submit), manager_review (role: Store Manager, options approve and reject) and the two end steps refund_approved and refund_rejected. Assign the Store Manager role in the Roles module so the right person sees each request.
Then create an API key in the API Keys module. Every request sends it in the api-key header.
How do you call Agilit-e from the POS backend?
One small helper keeps every call consistent. It adds the API key, sends JSON and turns Agilit-e's error object (statusCode, errorMessage, additionalMessages) into a readable exception.
javascript
// posFlow.js (Node 18+, uses the built-in fetch)
const BASE_URL = process.env.AGILITE_URL || "https://api.agilite.io";
const API_KEY = process.env.AGILITE_API_KEY;
const KEYS = {
receiptNumbering: "pos-receipt", // Numbering profile
refundNumbering: "pos-refund", // Numbering profile
receiptTemplate: "pos-receipt-html", // Templates profile
refundProcess: "pos-refund-approval" // BPM profile
};
async function agilite(path, { method = "POST", headers = {}, body } = {}) {
const res = await fetch(${BASE_URL}${path}, {
method,
headers: { "api-key": API_KEY, "Content-Type": "application/json", ...headers },
body: body === undefined ? undefined : JSON.stringify(body),
});
const text = await res.text();
if (!res.ok) {
let message = text;
try { message = JSON.parse(text).errorMessage || text; } catch { / plain text / }
throw new Error(Agilit-e ${path} failed (${res.status}): ${message});
}
return text;
}
The base URL is https://api.agilite.io for the cloud service. For an on-premise or container install, point AGILITE_URL at your own API Server instead.
How do you generate a receipt number?
javascript
// 1. Receipt and refund numbers
async function nextNumber(profileKey, storeCode) {
const value = await agilite("/numbering/generate", {
headers: { "profile-key": profileKey },
body: { param1: storeCode }, // available to the profile's Mustache tags
});
return value.trim(); // text/plain, e.g. "JHB01-000124"
}
The generate endpoint returns plain text, not JSON, which is why the helper reads res.text(). Pass the store code as param1 so the profile can build numbers like JHB01-000124.
One rule matters more than the code: generate the number once, save it with the sale, and reuse it on every retry. If the till loses its connection after the number comes back and simply asks again, you burn a number and leave a gap in the sequence. The same idempotency idea applies to every call between a till and a payment provider, and this guide on POS API integration covers how to keep those calls safe when networks drop.
How do you render the receipt?
javascript
// 2. Customer receipt (HTML for email or print)
function formatLines(items) {
return items
.map(i => ${i.qty} x ${i.name} @ ${(i.priceMinor / 100).toFixed(2)})
.join("\n");
}
async function renderReceipt(receiptNo, items) {
return agilite("/templates/execute", {
headers: { "profile-key": KEYS.receiptTemplate },
body: { param1: receiptNo, param2: formatLines(items) },
});
}
The template execute endpoint documents two string inputs, param1 and param2, so the line items go in as one pre-formatted block. Keep money in minor units (cents) in your database and only format it here, at the edge.
How do you keep a PDF copy?
javascript
// 3. Receipt PDF (PDFMake document definition)
async function receiptPdf(receiptNo, items, totalMinor) {
const meta = await agilite("/utils/generatePDF", {
body: {
content: [
{ text: Receipt ${receiptNo}, style: "header" },
...items.map(i => ({
columns: [${i.qty} x ${i.name}, { text: (i.priceMinor * i.qty / 100).toFixed(2), alignment: "right" }],
})),
{ text: Total: ${(totalMinor / 100).toFixed(2)}, marginTop: 10 },
],
},
});
return JSON.parse(meta); // metadata (_id, data.fileName), not the file itself
}
The body is a PDFMake document definition. The response is metadata about the stored file (_id, data.fileName), not the PDF itself, so save the _id against the sale and fetch the file when a customer asks for a copy.
How do you send a refund for approval?
javascript
// 4. Refund approval through BPM
async function requestRefund({ receiptNo, amountMinor, reason, cashier }) {
const refundNo = await nextNumber(KEYS.refundNumbering, receiptNo.split("-")[0]);
const first = JSON.parse(await agilite("/bpm/registerBPMRecord", {
method: "GET",
headers: { "process-key": KEYS.refundProcess, "current-user": cashier },
}));
const recordId = first.recordId || first._id; // check which field your server returns
const next = JSON.parse(await agilite("/bpm/execute", {
headers: {
"process-key": KEYS.refundProcess,
"bpm-record-id": recordId,
"option-selected": "submit",
"current-user": cashier,
"current-step": first.key,
"comments": ${refundNo} | ${receiptNo} | ${(amountMinor / 100).toFixed(2)} | ${reason},
},
body: {},
}));
return { refundNo, recordId, step: next.key, approvers: next.responsibleUsers };
}
Registering a record puts it in the first step (refund_requested). Executing the submit option moves it to manager_review, and BPM resolves who is responsible through the role on that step. The comments header lands in the record's history, which is why the refund reference, receipt number, amount and reason go there: anyone reading the history later sees the full story without opening another system.
The manager's app shows pending records and calls this when they decide:
javascript
async function decideRefund({ recordId, currentStep, manager, approve, note }) {
const step = JSON.parse(await agilite("/bpm/execute", {
headers: {
"process-key": KEYS.refundProcess,
"bpm-record-id": recordId,
"option-selected": approve ? "approve" : "reject",
"current-user": manager,
"current-step": currentStep,
"comments": note,
},
body: {},
}));
return step.key; // e.g. "refund_approved" or "refund_rejected"
}
Only when the step comes back as refund_approved does the POS send the refund to the payment provider. A rejected refund never reaches the card network.
What should you watch out for?
Step and option names must match the BPM profile exactly. current-step and option-selected are compared with what you configured, so a typo returns a 400 error.
current-user is not authentication. It records who acted. Make sure your own app has already checked that the person is signed in and holds the right role before you send it.
Locks. BPM records can be locked while someone works on them. If two managers open the same refund, handle the lock instead of letting the second click fail silently.
Small refunds. Many stores skip approval below a set amount. Do that check in your POS before registering a record, so managers only see refunds that need them.
Fraud patterns. The BPM history gives you a clean log of who requested and approved each refund. That data is exactly what fraud detection needs, and this walkthrough on how to integrate AI into POS software shows how teams turn refund and void history into automatic flags.
Keep the API key on the server. Tills call your backend, and only the backend calls Agilit-e.
How did I test this?
I ran the code above against a mocked API Server to confirm the calls go out in the right order with the right headers: two numbering calls, one template call, one PDF call, one record registration (GET, no body) and two execute calls (submit, then approve). Before going live, run the same flow against your own profiles in a test environment, because the response fields you get back depend on your BPM setup.
Frequently asked questions
Can Agilit-e generate unique receipt numbers for several POS terminals? Yes. The Numbering module's generate endpoint returns a unique number from a central profile, so every till that calls it draws from the same counter instead of keeping its own.
How do you build a refund approval workflow in Agilit-e? Create a BPM profile with a request step, a manager review step and approved and rejected end steps, register a record with /bpm/registerBPMRecord, and move it between steps with /bpm/execute using the option the user chose.
Which header does Agilit-e use for authentication? Every call to the API Server sends the API key in the api-key header. Numbering and Templates calls also send profile-key, and BPM calls send process-key.
Can Agilit-e create PDF receipts? Yes. The /utils/generatePDF utility takes a PDFMake document definition and returns metadata for the stored PDF, which you can fetch later.
Does the BPM module keep an audit trail of refunds? Yes. Each BPM record keeps a history of the steps it passed through, who acted and the comments they added, which works as an approval audit trail.

