Product QR cashback is everywhere in India now: scratch the hidden panel on a pack, scan, and money lands in your wallet. It looks simple from the outside. Under the hood, a scan to win assured cashback campaign is a small security system that has to stop reuse, guessing, and counterfeit packs, while still responding in under a second.
Here is how a system like Assured Rewards approaches the problem, and what any developer building something similar should think about.
1. Code generation: make guessing pointless
Each pack gets a unique code. If codes are sequential, someone will script through them. So:
- Generate codes from a cryptographically secure random source, not
Math.random(). - Use enough entropy. A 12 character base32 code gives about 60 bits, which makes brute force impractical.
- Store only a hash of the code plus a short lookup prefix, so a database leak does not leak redeemable codes.
import crypto from "node:crypto"; const ALPHABET = "ABCDEFGHJKLMNPQRSTUVWXYZ23456789"; // no 0/O, 1/I confusion export function newCode(len = 12) { const bytes = crypto.randomBytes(len); return [...bytes].map(b => ALPHABET[b % ALPHABET.length]).join(""); } 2. The scratch layer is a physical access control
The code is printed under a scratch panel so it cannot be read on the shelf. That matters: without it, anyone in the store could photograph codes and redeem them before the buyer gets home. The QR on the outside can carry the campaign and batch, while the hidden part carries the secret.
3. Redemption must be atomic
The core rule is simple: one code, one reward. Two people scanning the same code at the same second must not both get paid.
UPDATE codes SET redeemed_at = now(), redeemed_by = $1 WHERE code_hash = $2 AND redeemed_at IS NULL RETURNING campaign_id, reward_amount; If zero rows come back, the code was already used or never existed. Both are useful signals.
4. Turn failed scans into anti counterfeit data
A code that does not exist, or one that was already redeemed in another city, is often a sign of a fake or copied pack. Log the location, device and time of every failed scan. Clusters of failures around one distributor or market are exactly what a brand's anti counterfeit team wants to see. This is why the same scan that pays cashback also works as a genuine product check.
5. Wallet first, payout later
Crediting a bank account directly on every scan is slow and expensive. A better pattern:
- Credit an internal wallet instantly (an append only ledger entry).
- Let the user withdraw in one go through UPI, or redeem the balance on gift cards.
- Run payouts through a queue with retries and idempotency keys, so a timeout never pays twice.
6. Rate limits and fraud rules
- Limit scans per user, per device and per IP per hour.
- Flag accounts that redeem far more codes than a normal buyer could.
- Require sign in before credit, so rewards attach to a verified phone number.
Wrap up
A good scan to win campaign feels instant and generous to the buyer, and boring and predictable to the finance team. Secure code generation, atomic redemption, a ledger based wallet and solid fraud rules are what make assured cashback possible. If you want to see the consumer side of this flow, Assured Rewards is a live example of QR cashback with genuine product verification and UPI withdrawal.