Auto Debit
Personal
Business
Auto Debit is a service that automatically deducts an amount from your customer's account and transfers it to your business account to automatically renew service plans, settle orders, collect recurring fees, and more.
Steps to Integrate Auto Debit
Below are the steps to integrate Auto Debit into your product.
-
Create a grant /grant/token with
scopesset toauto_debit. -
Open the Cas Link interface using the
grantTokenreturned in the previous step. See details -
After the user completes authentication, your frontend will receive a
publicToken. Use thispublicTokento obtain anaccessTokenfor the grant. -
Once you have the
accessToken, call the Auto Debit account identity API to verify the account information. -
Call the Auto Debit API to create an automatic debit order for renewing your customer's service plan, settling orders, and more.
-
When an Auto Debit transaction is processed successfully or fails, the Cas system sends a webhook with the details in the
autoDebitfield. When your system receives this notification, it should re-verify the payment information and continue with the next steps.
Call API
Create access grant for Auto Debit
- 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": "auto_debit",
"language": "vi",
"redirectUri": "https://your-domain.vn/link",
}'
const axios = require('axios');
const data = JSON.stringify({
"scopes": "auto_debit",
"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 API details, see 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 API details, see here
Get the identity of the auto debit account
- CURL
- Javascript (Axios)
curl --location 'https://sandbox.bankhub.dev/identity/auto-debit' \
--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/identity/auto-debit',
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 API details, see here
Create an Auto Debit order
- CURL
- Javascript (Axios)
curl -L 'https://sandbox.bankhub.dev/auto-debit' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H 'x-client-id: <x-client-id>' \
-H 'x-secret-key: <x-client-id>' \
-d '{
"batchId": "35175743-763c-11ef-a291-0022481a0395",
"payments": [
{
"grantAccessToken": "string",
"paymentId": "56f21066-763c-11ef-a291-0022481a0395",
"amount": 2000,
"description": "Test Auto Debit"
}
]
}'
const axios = require('axios');
const data = JSON.stringify({
"batchId": "35175743-763c-11ef-a291-0022481a0395",
"payments": [
{
"grantAccessToken": "string",
"paymentId": "56f21066-763c-11ef-a291-0022481a0395",
"amount": 2000,
"description": "Test Auto Debit"
}
]
});
const config = {
method: 'post',
maxBodyLength: Infinity,
url: 'https://sandbox.bankhub.dev/auto-debit',
headers: {
'X-BankHub-Api-Version': '2023-01-01',
'x-client-id': '<x-client-id>',
'x-secret-key': '<x-client-id>'
},
data
};
axios.request(config)
.then((response) => {
console.log(JSON.stringify(response.data));
})
.catch((error) => {
console.log(error);
});
For API details, see here