Official ABA KHQR payment integration with two flexible checkout UIs and real-time payment confirmation.
Powered by: Anajak API + ABA PayWay
Deployment: Railway (free tier available)
Status: Production Ready π
payment-test/
βββ app.py # Flask backend
βββ fast_khqr.py # CLI tool
βββ requirements.txt # Dependencies
βββ Dockerfile # Container setup
βββ railway.json # Railway config
βββ Procfile # Process file
β
βββ templates/
β βββ index.html # Fast KHQR UI
β βββ checkout.html # ABA Checkout UI (NEW)
β
βββ static/
β βββ aba-checkout.min.js # ABA SDK (NEW)
β
βββ README.md # This file
βββ ABA_INTEGRATION.md # Full integration guide
βββ RAILWAY.md # Deployment guide
Best for: Quick QR code scanning
URL: http://localhost:5000/ or https://your-app.railway.app/
- Enter amount
- Generate KHQR code
- Scan with ABA Mobile app
- Real-time payment confirmation
- Download receipt as PDF
Best for: Full payment flow with multiple methods
URL: http://localhost:5000/checkout or https://your-app.railway.app/checkout
- Enter amount
- Choose: KHQR or ABA Pay
- Official ABA checkout modal
- Scan or wallet payment
- Auto-redirect on success
pip install -r requirements.txtpython app.pyFast KHQR: http://localhost:5000/
ABA Checkout: http://localhost:5000/checkout
Health Check: http://localhost:5000/health
git add .
git commit -m "Ready for Railway deployment"
git pushThen:
- Go to https://railway.app
- Create new project
- Connect GitHub repo
- Railway auto-deploys with Dockerfile
- Your app goes live! π
Edit templates/checkout.html around line 279:
merchant_id: 'YOUR_MERCHANT_ID', // β Replace with your ABA Merchant IDGet your Merchant ID:
- ABA PayWay Portal: https://checkout.payway.com.kh
- Contact ABA: support@ababank.com
- Usually looks like:
ABAPAYFB405176Y
POST /generate
ββ Request: { amount: 1000 }
ββ Response: { success, qr_url, qr_string, tran_id, client_id, expire_in_sec }
POST /check
ββ Request: { tran_id, client_id }
ββ Response: { meta: { qr_scanned, payment_approved, finished } }
GET /status-stream
ββ Query: ?tran_id=...&client_id=...
ββ Response: Server-Sent Events (real-time updates)
GET /health
ββ Response: { status: "ok", redis: "ready", upstream: {...} }
GET /download-receipt
ββ Query: ?tran_id=...&merchant=...&amount=...¤cy=...
ββ Response: PDF file download
GET /static/<file>
ββ Serves: JavaScript, CSS, images from `static/` folder
# Terminal 1: Start server
python app.py
# Terminal 2: Test generation
curl -X POST http://localhost:5000/generate \
-H "Content-Type: application/json" \
-d '{"amount": 1000}'
# Test health
curl http://localhost:5000/health- Go to
http://localhost:5000/ - Enter amount:
1000KHR - Click "Generate KHQR"
- QR appears (from Anajak API)
- Can download or display in ABA Mobile
Use the included CLI for automation:
# Generate + save QR image
python fast_khqr.py 1500
# Raw QR string (for scripts)
python fast_khqr.py 250 --raw
# Watch until paid
python fast_khqr.py 1000 --watch
# Check previous transaction
python fast_khqr.py --status TID-123456 client-id-xyz
# Verify API health
python fast_khqr.py --healthBoth UIs are fully responsive:
- Open in Safari
- Test KHQR with ABA Mobile app
- Scan QR code
- Open in Chrome
- Test with ABA Mobile app
- Full payment flow works
- β HTTPS enabled (Railway auto)
- β 256-bit SSL encryption
- β No sensitive data in logs
- β Secure Server-Sent Events
- β CORS configured for ABA
- β Input validation on all endpoints
// In templates/checkout.html line ~279
merchant_id: 'YOUR_PRODUCTION_MERCHANT_ID',git add .
git commit -m "Production ready"
git push origin main- Go to https://railway.app
- Sign up (free tier available)
- Create new project
- Select GitHub repository
- Railway auto-detects Docker setup
- Deploy happens automatically
- Your app goes live at:
https://your-project-name.railway.app
- Dashboard: View logs in real-time
- Alerts: Set up optional notifications
- Metrics: Monitor CPU, memory, requests
| File | Purpose |
|---|---|
app.py |
Flask backend, all API endpoints |
templates/index.html |
Fast KHQR UI |
templates/checkout.html |
ABA Checkout UI |
static/aba-checkout.min.js |
ABA Payway SDK |
requirements.txt |
Python packages |
Dockerfile |
Container image |
railway.json |
Railway config |
ABA_INTEGRATION.md |
Full integration docs |
RAILWAY.md |
Deployment guide |
- Check:
curl http://localhost:5000/health - Verify internet connection
- Check Anajak API status
- Check browser console (F12 β Console)
- Look at Network tab for SSE connection
- Verify tran_id and client_id are valid
- Ensure
static/folder exists - Check file paths match in HTML
- Restart Flask server
- Verify
aba-checkout.min.jsloaded (check Network tab) - Check merchant_id is set in checkout.html
- Look for JavaScript errors in console
- ABA_INTEGRATION.md - Complete integration guide
- RAILWAY.md - Railway deployment steps
- Anajak API - API reference
- ABA PayWay - Official docs
β
Real-time QR code generation
β
Server-Sent Events for instant updates
β
PDF receipt generation
β
Official ABA checkout integration
β
Multiple payment methods (KHQR + ABA Pay)
β
Mobile responsive UI
β
Health check endpoint
β
Full error handling
β
Railway deployment ready
β
Docker containerized
β
Production secure
-
Local Testing
python app.py # Visit: http://localhost:5000/ -
Configure Merchant ID
- Edit
templates/checkout.html - Add your ABA Merchant ID
- Edit
-
Deploy to Railway
git push # Railway auto-deploys -
Go Live
- Your app:
https://your-project.railway.app - Share the URL with customers
- Your app:
Anajak Issues: https://anajak.site
ABA PayWay: Contact ABA Bank
Railway Help: https://docs.railway.app
This integration is free to use. Follow ABA Bank and Anajak terms of service.
- The Anajak
POST /api/create-qrrequires a valid ABA PayWay merchanturl+amount. client_id+tran_idare required together for/check-status.- Upstream can occasionally return 5xx during ABA link navigation (the CLI and backend have light retries).
- When
download_qris present we use it directly (fast + canonical image). Localqrcode+pillowonly as rare fallback.
GET https://api.anajak.site/healthPOST https://api.anajak.site/api/create-qrPOST https://api.anajak.site/api/check-status
Built for fast merchant checkout flows.
For the simplest experience on Windows (no typing commands):
| File | What it does | How to use |
|---|---|---|
run.bat |
Menu with all options | Double-click β choose 1, 2 or 3 |
start-web.bat |
Starts the web interface + opens browser | Double-click |
generate-khqr.bat |
Prompts for amount and generates QR | Double-click β type amount |
Recommended: Just double-click run.bat β it gives you a simple menu.
Note: These .bat files assume
pythonis available in your PATH and you have already runpip install -r requirements.txtat least once.
- No more custom receipt UI: We removed the built HTML receipt box completely.
- Real PDF Receipt like ABA: "Download Receipt (PDF)" button generates and downloads a clean professional PDF receipt (styled exactly like official ABA Bank receipts - blue header, transaction summary, highlighted total, thank you footer).
- Clean ABA-like Success Message: On approval, the UI loads a modern, clean bank-style success screen with green check icon, "Payment Successful", simple transaction details list, and ABA blue "Thank you for your payment!" message.
- ABA-style Background + UX: Light blue success background, deep #003087 accents, professional clean layout like a real bank account / payment confirmation page.
- Cancel Payment and Back to Main Page still available for smooth flow.
- Generate flow: Immediate loading spinner + status text ("Contacting Anajak API..."). Button and input are disabled instantly. Uses the pre-generated
qr_urlfrom Anajak/ABA (fastest possible QR image β no local generation delay). - Payment status checking: Replaced client-side polling with Server-Sent Events (SSE).
- Server internally checks Anajak every 0.8 seconds (faster detection of scan/approval).
- Only pushes updates to the browser when something actually changes (scanned / approved).
- Feels instant and lag-free on the client. Much better than fixed interval polling.
- Generate flow now has a smoother finally block β no button/input state flicker when transitioning to the QR screen.
- Smooth CSS transitions, fade-in animations, and button press feedback throughout.
- Overall: More responsive "bank-like" feel with less perceived waiting.
- Download Receipt (PNG): Click β¬ Download Receipt (PNG) for a high-quality image of the receipt.
- Print / Save as PDF: Opens a printer-friendly version (use "Save as PDF" in the dialog).
- Receipt includes: Merchant, Amount, Tran ID, Paid time, Method, Status + small QR reference image.