VNPay, MoMo, ZaloPay, OnePay Signature API
Build signed VNPay, MoMo, ZaloPay and OnePay requests, verify return URLs, IPNs and callbacks, and see the exact signed string to fix “invalid signature”.
action=create builds a ready request: the VNPay payment URL (vnp_ fields sorted, encoded like PHP urlencode, HMAC-SHA512 vnp_SecureHash, API 2.1.0), the MoMo v2 body with its HMAC-SHA256 signature over the fixed rawSignature, the ZaloPay order with mac = HMAC-SHA256(key1, app_id|app_trans_id|app_user|amount|app_time|embed_data|item), or the OnePay URL with the upper-case HMAC-SHA256 vpc_SecureHash (hex-decoded secure secret, sorted vpc_ / user_ fields). action=query signs the MoMo and ZaloPay status queries.
action=verify takes the return URL / IPN query string (query) or the JSON body (fields) and recomputes the signature: valid, the expected and received values, the decoded order id, amount and response code, and signed_data – the exact string that was signed. Send your own signed string in signed_data and the answer points to the first character that differs. ZaloPay callbacks (data + mac, key2) and redirect checksums are supported. action=codes explains vnp_ResponseCode, vnp_TransactionStatus, MoMo resultCode, ZaloPay return_code / sub_return_code and OnePay vpc_TxnResponseCode in Vietnamese and English.
The API never contacts the gateways and never stores or returns the secret (secret, or key1 / key2 for ZaloPay). Use sandbox credentials while developing; keep production secrets on your own server.
Markdown · OpenAPI · Postman · llms.txt
Parameters
| Name | In | Type | Required | Default | |
|---|---|---|---|---|---|
provider | body|query | string | yes | vnpay, momo, zalopay or onepay. | |
action | body|query | string | no | codes | create, verify, query (MoMo, ZaloPay) or codes (alias mode). |
secret | body | string | no | vnp_HashSecret, MoMo secretKey or OnePay secure secret (hex). ZaloPay: key1 (create / query) or key2 (verify). Never returned. | |
query | body | string | no | Verify: the full return URL / IPN query string. | |
fields | body | object | no | Verify: the JSON body (MoMo IPN, ZaloPay callback); create: extra provider fields (vnp_…, vpc_…). | |
amount | body | number | no | Create: amount in VND (the API multiplies by 100 where the gateway expects it). | |
order_id | body | string | no | Create: your order reference (vnp_TxnRef, orderId, app_trans_id suffix, vpc_MerchTxnRef). | |
tmn_code / access_key / partner_code / app_id / merchant / access_code | body | string | no | Create: merchant identifiers of VNPay / MoMo / ZaloPay / OnePay. | |
return_url / ipn_url | body | string | no | Create: customer return URL (MoMo redirectUrl) and MoMo ipnUrl. | |
signed_data | body | string | no | Verify: your own signed string, to locate the first difference. | |
environment | body|query | string | no | sandbox | sandbox or production (gateway URLs). |
code | query | string | no | Codes: one response code to explain. |
Example
curl -X POST "https://apibox.io.vn/v1/vn-pay-gateway" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"provider":"vnpay","action":"create","secret":"SANDBOXSECRETKEY0123456789ABCDEF","tmn_code":"DEMOV210","amount":150000,"order_id":"DH001","order_info":"Thanh toan don hang DH001","return_url":"https://shop.example/vnpay_return","create_date":"20261115103000","expire_date":"20261115104500"}'const res = await fetch('https://apibox.io.vn/v1/vn-pay-gateway', {
method: 'POST',
headers: {
Authorization: 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json',
},
body: JSON.stringify({
"provider": "vnpay",
"action": "create",
"secret": "SANDBOXSECRETKEY0123456789ABCDEF",
"tmn_code": "DEMOV210",
"amount": 150000,
"order_id": "DH001",
"order_info": "Thanh toan don hang DH001",
"return_url": "https://shop.example/vnpay_return",
"create_date": "20261115103000",
"expire_date": "20261115104500"
}),
});
const data = await res.json();
console.log(data);import requests
res = requests.post(
"https://apibox.io.vn/v1/vn-pay-gateway",
headers={"Authorization": "Bearer YOUR_API_KEY"},
json={"provider": "vnpay", "action": "create", "secret": "SANDBOXSECRETKEY0123456789ABCDEF", "tmn_code": "DEMOV210", "amount": 150000, "order_id": "DH001", "order_info": "Thanh toan don hang DH001", "return_url": "https://shop.example/vnpay_return", "create_date": "20261115103000", "expire_date": "20261115104500"},
timeout=30,
)
print(res.json())<?php
$ch = curl_init('https://apibox.io.vn/v1/vn-pay-gateway');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_HTTPHEADER => ['Authorization: Bearer YOUR_API_KEY', 'Content-Type: application/json'],
CURLOPT_POSTFIELDS => '{"provider":"vnpay","action":"create","secret":"SANDBOXSECRETKEY0123456789ABCDEF","tmn_code":"DEMOV210","amount":150000,"order_id":"DH001","order_info":"Thanh toan don hang DH001","return_url":"https://shop.example/vnpay_return","create_date":"20261115103000","expire_date":"20261115104500"}',
]);
$response = curl_exec($ch);
print_r(json_decode($response, true));Response
{
"provider": "vnpay",
"action": "create",
"environment": "sandbox",
"payment_url": "https://sandbox.vnpayment.vn/paymentv2/vpcpay.html?vnp_Amount=15000000&vnp_Command=pay&vnp_CreateDate=20261115103000&vnp_CurrCode=VND&vnp_ExpireDate=20261115104500&vnp_IpAddr=127.0.0.1&vnp_Locale=vn&vnp_OrderInfo=Thanh+toan+don+hang+DH001&vnp_OrderType=other&vnp_ReturnUrl=https%3A%2F%2Fshop.example%2Fvnpay_return&vnp_TmnCode=DEMOV210&vnp_TxnRef=DH001&vnp_Version=2.1.0&vnp_SecureHash=764fe85f07a9a71b9ba519f7f36c1ec6798f78aa58f89fdd84defa720140866bd670b0612c646aeb95ea0e7cc5c9df2e09b9694c184a0cfb3f37af9bb3eaa3b9",
"fields": {
"vnp_Version": "2.1.0",
"vnp_Command": "pay",
"vnp_TmnCode": "DEMOV210",
"vnp_Amount": "15000000",
"vnp_CreateDate": "20261115103000",
"vnp_CurrCode": "VND",
"vnp_IpAddr": "127.0.0.1",
"vnp_Locale": "vn",
"vnp_OrderInfo": "Thanh toan don hang DH001",
"vnp_OrderType": "other",
"vnp_ReturnUrl": "https://shop.example/vnpay_return",
"vnp_TxnRef": "DH001",
"vnp_ExpireDate": "20261115104500",
"vnp_SecureHash": "764fe85f07a9a71b9ba519f7f36c1ec6798f78aa58f89fdd84defa720140866bd670b0612c646aeb95ea0e7cc5c9df2e09b9694c184a0cfb3f37af9bb3eaa3b9"
},
"signed_data": "vnp_Amount=15000000&vnp_Command=pay&vnp_CreateDate=20261115103000&vnp_CurrCode=VND&vnp_ExpireDate=20261115104500&vnp_IpAddr=127.0.0.1&vnp_Locale=vn&vnp_OrderInfo=Thanh+toan+don+hang+DH001&vnp_OrderType=other&vnp_ReturnUrl=https%3A%2F%2Fshop.example%2Fvnpay_return&vnp_TmnCode=DEMOV210&vnp_TxnRef=DH001&vnp_Version=2.1.0",
"algorithm": "HMAC-SHA512(vnp_HashSecret, signed_data), hex",
"note": "Fields sorted by name, keys and values encoded like PHP urlencode (space = \"+\"), empty values skipped, vnp_SecureHash / vnp_SecureHashType excluded. Redirect the customer to payment_url; never trust the return URL alone – update the order from the IPN.",
"secret_used": "in memory only, not logged or returned",
"reviewed": "2026-11-15",
"disclaimer": "Signing helper for integration and debugging. Prefer sandbox credentials; production secrets should stay on your own server."
}
Use cases
- Find why VNPay answers “Sai chữ ký” (code 97) or MoMo answers 13
- Build payment links from Google Apps Script, n8n or a no-code tool without an SDK
- Verify IPN / callback signatures in a test suite
- Explain gateway response codes to support staff
FAQ
Why does my VNPay signature not match?
Usually the encoding: VNPay signs keys and values encoded like PHP urlencode (space = “+”), sorted by name, without vnp_SecureHash. Compare signed_data with your string – the API shows the first difference.
Is my secret safe?
It is only used in memory to compute the HMAC; it is not logged or returned. For production keys, prefer computing the signature on your own server.
Does the API send the payment to the gateway?
No. It only builds and checks signatures; your server calls the gateway.
Related APIs
Hash Generator
Compute MD5, SHA-1, SHA-256, SHA-384, SHA-512 and CRC32 of text or files in one call, as hex or base64, with optional HMAC signing.
B64Encode / Decode
Encode or decode text as Base64, Base64URL, hex, URL encoding, HTML entities, Unicode escapes, ROT13 or binary with one simple API call.
***Password Generator
Generate cryptographically secure random passwords (4–256 chars, up to 100 at once) or check a password’s strength, entropy and estimated crack time.