QR Pay
Create QR payment
QR PAY is a dynamic QR code generated per order with a built-in payment confirmation.
For each generated payment QR code, a virtual account number is also created and linked to a corresponding order.
When the customer makes a payment to this virtual account, the associated order is automatically marked as successfully paid.
When the customer pays to the virtual account number with the exact amount or exact amount and description,
Cas will confirm that your order has been paid.
Your system will receive a webhook
of type TRANSACTIONS
,
and the paymentMeta
will contain the referenceNumber
value associated with the QR Pay created earlier.
Steps to Integrate QR Pay
Below are the steps to integrate QR Pay into your product.
-
Create a grant
/grant/token
withscopes
set toqrpay
. -
Open the Cas Link interface using the
grantToken
returned in the previous step.See details
-
After the user completes the authentication, your frontend will receive a
publicToken
, which you can use to obtain anaccessToken
for the grant. -
Once you have the
accessToken
, call theGet QR Pay Account Identity API
to verify if the account is valid.
If the account is invalid, you should call the/grant/remove API
to revoke the grant. -
You can now call the
Create QR Pay API
. -
Generate the QR code from the
qrCode
field in the response and display it in your interface.
To simplify generating VietQR codes, you can use theQuicklink from vietqr.io
to generate the QR code and embed the link into your system. -
Handle the order status in your system when receiving a transaction
webhook
,
and thereferenceNumber
in thepaymentMeta
from the webhook corresponds to your internal order ID.
Call API
Create Grant Token for QR Pay
- CURL
- Javascript (Axios)
curl --location 'https://sandbox.bankhub.dev/grant/token' \
--header 'X-BankHub-Api-Version: 2023-01-01' \
--header 'x-client-id: <CLIENT_ID_HERE>' \
--header 'x-secret-key: <SECRET_KEY_HERE>' \
--header 'Content-Type: application/json' \
--data '{
"scopes": "qrpay",
"language": "vi",
"redirectUri": "https://your-domain.vn/link",
}'
const axios = require('axios');
const data = JSON.stringify({
"scopes": "qrpay",
"language": "vi",
"redirectUri": "https://your-domain.vn/link",
});
const config = {
method: 'post',
maxBodyLength: Infinity,
url: 'https://sandbox.bankhub.dev/grant/token',
headers: {
'X-BankHub-Api-Version': '2023-01-01',
'x-client-id': '<CLIENT_ID_HERE>',
'x-secret-key': '<SECRET_KEY_HERE>',
'Content-Type': 'application/json'
},
data: data
};
axios.request(config)
.then((response) => {
console.log(JSON.stringify(response.data));
})
.catch((error) => {
console.log(error);
});
For detail API, here
Get accessToken from publicToken
- CURL
- Javascript (Axios)
curl --location 'https://sandbox.bankhub.dev/grant/exchange' \
--header 'X-BankHub-Api-Version: 2023-01-01' \
--header 'x-client-id: <CLIENT_ID_HERE>' \
--header 'x-secret-key: <SECRET_KEY_HERE>' \
--header 'Content-Type: application/json' \
--data '{
"publicToken": "bdbde2bad-7685-4f95-987c-71309a4a3"
}'
const axios = require('axios');
const data = JSON.stringify({
"publicToken": "bdbde2bad-7685-4f95-987c-71309a4a3"
});
const config = {
method: 'post',
maxBodyLength: Infinity,
url: 'https://sandbox.bankhub.dev/grant/exchange',
headers: {
'X-BankHub-Api-Version': '2023-01-01',
'x-client-id': '<CLIENT_ID_HERE>',
'x-secret-key': '<SECRET_KEY_HERE>',
'Content-Type': 'application/json'
},
data: data
};
axios.request(config)
.then((response) => {
console.log(JSON.stringify(response.data));
})
.catch((error) => {
console.log(error);
});
For detail API, here
Retrieve the Identity Information of the Account for QR Pay Creation
- CURL
- Javascript (Axios)
curl --location 'https://sandbox.bankhub.dev/qr-pay/identity' \
--header 'X-BankHub-Api-Version: 2023-01-01' \
--header 'Authorization: <ACCESS_TOKEN_HERE>' \
--header 'x-client-id: <CLIENT_ID_HERE>' \
--header 'x-secret-key: <SECRET_KEY_HERE>'
const axios = require('axios');
const config = {
method: 'get',
maxBodyLength: Infinity,
url: 'https://sandbox.bankhub.dev/qr-pay/identity',
headers: {
'X-BankHub-Api-Version': '2023-01-01',
'Authorization': '<ACCESS_TOKEN_HERE>',
'x-client-id': '<CLIENT_ID_HERE>',
'x-secret-key': '<SECRET_KEY_HERE>''
}
};
axios.request(config)
.then((response) => {
console.log(JSON.stringify(response.data));
})
.catch((error) => {
console.log(error);
});
For detail API, here
Create QR Pay
- CURL
- Javascript (Axios)
curl --location 'https://sandbox.bankhub.dev/qr-pay' \
--header 'X-BankHub-Api-Version: 2023-01-01' \
--header 'Authorization: <ACCESS_TOKEN_HERE>' \
--header 'x-client-id: <CLIENT_ID_HERE>' \
--header 'x-secret-key: <SECRET_KEY_HERE>'
--data '{
"amount": 2000,
"description": "cassotest",
"referenceNumber": "1234455811acbc"
}'
const axios = require('axios');
const data = JSON.stringify({
"amount": 2000,
"description": "cassotest",
"referenceNumber": "1234455811acbc"
});
const config = {
method: 'post',
maxBodyLength: Infinity,
url: 'https://sandbox.bankhub.dev/qr-pay',
headers: {
'X-BankHub-Api-Version': '2023-01-01',
'Authorization': '<ACCESS_TOKEN_HERE>',
'x-client-id': '<CLIENT_ID_HERE>',
'x-secret-key': '<SECRET_KEY_HERE>'
},
data
};
axios.request(config)
.then((response) => {
console.log(JSON.stringify(response.data));
})
.catch((error) => {
console.log(error);
});
For detail API, here