An Apple Wallet pass that updates itself
The card lives on the phone as a Wallet pass. I implemented the PassKit web service: when the barista adds a coffee, the server sends an empty APNs push and the iPhone downloads the updated pass, with the stamp strip rendered per request and a notice that tells an added coffee from a redeemed reward. The QR is signed, so it cannot be forged or guessed for another customer.
export const addCoffeeByToken = async (token: string) => {
if (!(await isAdmin())) return UNAUTHORIZED;
// Signed QR: a tampered or made-up code is rejected.
const id = verifyClientToken(token);
if (!id) return { error: "Código no válido." };
// A full card is redeemed instead of adding one.
return current.coffees >= COFFEES_TO_EXCHANGE
? applyRedeem(id, "scan")
: applyCoffeeAdded(id, "scan");
};
// After every change: an empty push tells the iPhone
// to fetch the pass again. No polling.
notifyPassChanged(id);




