Official client libraries and command-line tool for the KHPay payment gateway (Cambodia · ABA PayWay · KHQR).
API docs: https://khpay.site/api-documentation.php Get an API key: https://khpay.site/register
| Folder | Purpose | Install |
|---|---|---|
cli/ |
Node.js CLI (khpay login, khpay logs, khpay test, …) |
npm install -g khpay |
python/ |
Python SDK + CLI (same commands as Node) | pip install khpay |
php/ |
PHP SDK (server-side) | copy KHPay.php into your project |
js/ |
Browser JS SDK + embeddable widget | <script src="khpay.js"></script> |
woocommerce/ |
WooCommerce payment gateway plugin | upload zip via WP admin |
npm install -g khpay
khpay login # paste your ak_… key
khpay whoami
khpay test success # fires a safe test transaction (no real money)
khpay logs --status 400
khpay inspect 1842pip install khpay
khpay login
khpay whoamifrom khpay import KHPay
client = KHPay("ak_your_api_key")
payment = client.create_payment(10.00, "USD", "Order #123")
print(payment["data"]["payment_url"])require_once 'php/KHPay.php';
$khpay = new KHPay('ak_your_api_key');
$payment = $khpay->createPayment(10.00, 'USD', 'Order #123');All SDKs expose the same helper:
KHPay::verifyWebhookSignature($rawBody, $signatureHeader, $webhookSecret);KHPay.verify_webhook_signature(raw_body, signature, secret)Send X-Test-Mode: 1 with any request and use these magic amounts:
| Amount | Result |
|---|---|
1.00 |
Auto-success |
2.00 |
Declined |
3.00 |
Gateway down (502) |
4.00 |
Fraud-blocked |
The CLI's khpay test <scenario> command sets this automatically.
MIT — see LICENSE.
- Docs: https://khpay.site/api-documentation.php
- Status: https://khpay.site/status
- Issues: please open a GitHub issue on this repo
Official client libraries for the KHPAY Payment Gateway API.
| Language | Path | Min Version |
|---|---|---|
| PHP | sdk/php/KHPay.php |
PHP 8.0+ (curl) |
| JavaScript | sdk/js/khpay.js |
Node 18+ or any modern browser |
| Python | sdk/python/khpay.py |
Python 3.8+ (stdlib only) |
require_once 'sdk/php/KHPay.php';
$khpay = new KHPay('your_api_key');
// Create a payment
$payment = $khpay->createPayment(10.00, 'USD', 'Order #123');
echo $payment['data']['qr_url'];
// Check status
$status = $khpay->checkPayment('txn_abc123');
// Verify webhook signature
$isValid = KHPay::verifyWebhookSignature($rawBody, $signature, $webhookSecret);const KHPay = require('./sdk/js/khpay');
const client = new KHPay('your_api_key');
// Create a payment
const payment = await client.createPayment(10.00, 'USD', 'Order #123');
console.log(payment.data.qr_url);
// Check status
const status = await client.checkPayment('txn_abc123');
// Verify webhook
const valid = await KHPay.verifyWebhookSignature(body, sig, secret);from sdk.python.khpay import KHPay
client = KHPay('your_api_key')
# Create a payment
payment = client.create_payment(10.00, 'USD', 'Order #123')
print(payment['data']['qr_url'])
# Check status
status = client.check_payment('txn_abc123')
# Verify webhook
valid = KHPay.verify_webhook_signature(body, sig, secret)All SDKs support:
- QR payment generation (single & batch)
- Payment status checking
- Transaction listing & filtering
- Webhook CRUD & signature verification
- Scheduled/recurring payments
- API key rotation
- Account info & stats
All API requests require a Bearer token. Get your API key from the KHPAY dashboard under Settings.
Authorization: Bearer your_api_key_here
Each SDK throws typed exceptions on API errors with HTTP status code and error message from the server.