A decentralized, serverless loyalty and gamification platform designed to accelerate digital adoption for Cambodian MSMEs. Built on Cloudflare Pages and D1, this system integrates seamlessly with the BongHoey KHQR payment gateway to automatically convert customer payments into loyalty points.
- Automated Point Issuance: Customers earn points automatically when they pay via KHQR (Default: 1,000 KHR = 1 Point).
- 2-Step Verification: Uses BongHoey's
receipt.paidandreceipt.verifiedwebhooks to securely issue points only after merchant confirmation. - Frictionless Onboarding: Sends a "Magic Link" back to the BongHoey app so users can claim their points and secure their wallet with a 4-digit PIN.
- Gamified Lucky Draw: Customers can spend points to spin a weighted probability wheel for physical rewards (e.g., Free Coffee, Discounts).
- Shop Admin Portal: MSMEs can easily manage physical gift inventory, set win probabilities (rarity weights), and monitor stock.
This app runs 100% at the edge using:
- Frontend: React + Vite
- Backend: Cloudflare Pages Functions (Serverless APIs)
- Database: Cloudflare D1 (Serverless SQLite)
- Payment/OCR Gateway: BongHoey Webhooks
- Log into the Cloudflare Dashboard.
- Navigate to Workers & Pages -> D1 SQL Database.
- Click Create Database and name it
rewards_db. - Copy the Database ID (you will need this for your
wrangler.tomlfile).
- Push this repository to your GitHub account.
- Open
wrangler.tomland replacePASTE_YOUR_DATABASE_ID_HEREwith your actual D1 Database ID. - Commit the changes.
- In Cloudflare, go to Workers & Pages -> Create Application -> Pages -> Connect to Git.
- Select your GitHub repository.
- Build Settings:
- Framework preset:
None - Build command:
npm run build - Build output directory:
dist
- Framework preset:
- Environment Variables:
- Add a variable named
BONGHOEY_WEBHOOK_SECRET. Set it to a strong, random password (you will paste this into BongHoey later).
- Add a variable named
- Click Save and Deploy. Cloudflare will generate your live URL (e.g.,
https://pay-to-earn.pages.dev).
Once the deployment finishes, open your browser and visit:
https://YOUR_APP.pages.dev/api/init-db
You should see a success message. Your tables and starter gifts are now created!
To connect the payment gateway to your new app, you need to configure your BongHoey Merchant settings.
- Log into your BongHoey Merchant Dashboard.
- Navigate to the Webhook / Integrations settings.
- Webhook URL: Enter your Cloudflare Pages API endpoint:
https://YOUR_APP.pages.dev/api/webhook - Webhook Secret: Paste the exact same secret you used for
BONGHOEY_WEBHOOK_SECRETin Cloudflare. - Save the configuration.
For the system to track who made the payment, the customer must provide their phone number.
- Tell customers to type their Phone Number into the "Note / សំណួរ" field when they upload their bank receipt to BongHoey.
- User Scans & Uploads: Customer pays, uploads the receipt, and enters their phone number. BongHoey sends the
receipt.paidevent. - Magic Link Generated: Your app logs a pending transaction and sends back a Magic Link button.
- User Claims: The user clicks "Setup Account & Claim" in BongHoey, landing on your app to create a PIN.
- Shop Verifies: The MSME owner checks their bank app and approves the receipt in BongHoey. BongHoey sends the
receipt.verifiedevent. - Points Awarded: Your app converts the KHR amount to points and deposits them into the user's secured wallet!
To manage your physical gifts and adjust the Lucky Draw weights:
- Visit your app URL.
- Click Shop Admin Login.
- (Highly Recommended): Protect the
/adminUI route using Cloudflare Zero Trust so only authorized MSME staff can access the inventory management system.