# 30s One-Time HMAC QR & Stripe Fail-Closed Atomic Dispense for Smart Vending
> Canonical: https://space-bit.com/guides/smart-vending-30s-hmac-qr-stripe-atomic-dispense/ | Alternate: https://spacebit.cn/guides/smart-vending-30s-hmac-qr-stripe-atomic-dispense/

Shipping unattended coffee, ice, or retail kiosks in the UK or US? Learn how to drive high zero-install H5 checkout conversion while guaranteeing 0 screenshot replay fraud, 0 double-vends, and strict UK GDPR compliance.

## TL;DR Zero-Shrinkage Unattended Kiosk Laws (Citable Facts)
- 30s PII-Free One-Time HMAC QR Tokens: Encode only a short-lived server HMAC digest and random nonce—never member emails or phone numbers—invalidating on first scan to kill group-chat screenshot sharing.
- `RESERVED → COMMITTED / RELEASED` Row Locks: Acquire a transactional DB lock keyed by `Idempotency-Key` before actuating motors; deduct quota only on confirmed `COMMITTED` hardware completion.
- Always Fail-Closed Offline: When a kiosk drops offline, reject vend locking cleanly instead of trusting stale local token caches—eliminating physical shrinkage.
- Stripe `event.id` Deduplication + IANA DST Resets: Guard Stripe subscription webhooks on `event.id` uniqueness keys and compute midnight subscriber quota resets using `Europe/London` IANA rules.

## Unattended Kiosk Verification & Dispense Architecture Comparison
|Risk & Compliance Factor|30s HMAC QR + Fail-Closed Atomic Lock (Spacebit)|Static Member QR + Frontend Debounce|Offline Cached QR Verify & Delayed Sync|
|---|---|---|---|
|Screenshot Sharing Fraud|Expires in 30s & burns on first scan|One screenshot gets scanned across multiple kiosks|Unlimited offline replays before list sync|
|Double-Scan / Flaky 4G Vends|Row lock `RESERVED` + `Idempotency-Key` enforces 1 pour|Dual taps / retries routinely dispense two cups|Async ledger fails mutual exclusion|
|Stripe Webhook Replays|Unique `event.id` ledger prevents duplicate credits|Duplicate retries credit double monthly cups|Delayed revocation lets cancelled cards vend|
|UK / EU GDPR Privacy|Zero member PII in QR payloads or edge logs|Member phone/ID leaked visually in QR payload|Requires shipping member allowlists to kiosk|
|UK/EU Daylight Saving Switches|Exact `Europe/London` timezone boundary math|Hardcoded UTC offsets break quotas twice a year|Terminal RTCs drift without NTP DST handling|

## 4 Field-Proven Atomic Kiosk Patterns
### 01 · High-Conversion Zero-Install H5 Checkout + Strict Lock Boundary
Street shoppers rarely install a 50MB native app just for one iced coffee. Zero-install H5 / Stripe checkout converts walk-up traffic, while server-issued 30s tokens guard physical machine actuation.

### 02 · Bounded `RESERVED` Timeout Protects Shoppers From Jammed Motors
Equally critical as blocking doubles: if no physical vend confirmation returns within a strict hardware timeout (e.g. 25s), the engine auto-transitions to `RELEASED`, refunds/restores quota, and flags maintenance.

### 03 · Real-Time Stripe Subscription & Chargeback Enforcement
Handles `customer.subscription.updated` and `invoice.payment_failed` webhooks idempotently so delinquent plans stop locking dispenser actuators immediately.

### 04 · Single-Node Go + SQLite WAL Economics
Proven in London commercial operation: tuned SQLite WAL behind a single-binary Go service handles strict transactional row locks with zero expensive multi-zone DB overhead.

## FAQ
### Can we inspect or run your atomic vending lock and 30s HMAC QR implementation right away?
Yes—`tools/atomic_vending_guard.py` in our public GitHub kit (`bobobo2026/aiot-production-kit`) showcases 30s one-time HMAC verification and concurrent `RESERVED → COMMITTED/RELEASED` state tests.

### Does Fail-Closed hurt UX when kiosks sit inside weak shopping-center basements?
Our platform checks live kiosk heartbeat health prior to checkout authorization, gracefully warning shoppers or routing to an adjacent unit before taking funds if a machine is offline.

### Can this commerce engine support both UK/US Stripe currencies and multi-franchise revenue sharing?
Yes. We deploy GBP/USD/EUR/AUD Stripe Billing with optional Connect revenue splits alongside automated local-timezone VAT reporting.

### How quickly can Spacebit harden an existing vending fleet experiencing duplicate vends or fraud?
A 2–3 week Lean POC verifies 30s HMAC tokens and fail-closed hardware locking on one production kiosk before rolling out cleanly across your entire fleet in 4–8 weeks.
