/ Cases / Restaurants / Loyalty
The stamp card lives on the phone, pops up when the customer arrives and the agent can credit receipts. Automatic birthday gift.
0
apps to download
5 min
resync
/ The problem
Paper stamp cards get lost, and nobody downloads an app to collect coffees.
/ What we built
/ How it works
/ By the numbers
■ Real production data · counts per month, no amounts or personal data · Cumulative at month end.
/ Real code
// ⚠️ IGUALDAD, no `.length`: ver el encabezado. Un número inexistente pero
// bien formado devuelve la página entera sin filtrar.
const iguales = (datos.receipts ?? []).filter((r) => digitos(r.receipt_number) === d);
if (iguales.length === 0) return { ok: false, code: 'receipt_not_found' };
if (iguales.length > 1) {
// …
// no se adivina cuál es. Que el cajero mire el guion impreso.
return { ok: false, code: 'receipt_ambiguous', detalle: { opciones: iguales.map((r) => r.receipt_number).join(', ') } };
}
const r = iguales[0];
if (r.cancelled_at || r.receipt_type === 'REFUND') return { ok: false, code: 'receipt_cancelled' };
const tienda = tiendaDeRecibo(r.store_id);
if (!tienda) {
// Tienda nueva que nadie mapeó. NO se rechaza al cliente por un hueco
// nuestro: se acredita marcado y el panel lo muestra.
return { ok: true, estado: 'unverified', motivo: `store_id sin mapear: ${r.store_id}` };
}
if (tienda.sede !== o.sucursal) {
return { ok: false, code: 'receipt_wrong_store', detalle: { tienda: tienda.nombre, sede: tienda.sede } };
}
const ahora = o.ahora ?? new Date();
const horas = (ahora.getTime() - new Date(r.receipt_date).getTime()) / 3_600_000;
if (horas > VENTANA_HORAS) {
return { ok: false, code: 'receipt_too_old', detalle: { fecha: r.receipt_date.slice(0, 10), horas: Math.round(horas) } };
}
■ Before granting a stamp, the receipt is checked against the POS: exact number, not voided, from that location and from the last 48 hours.
/ Stack