Auto Debit
Personal
Business
Auto Debit (Thu phí tự động) là dịch vụ tự động trích một khoản tiền từ tài khoản của khách hàng và chuyển vào tài khoản của doanh nghiệp để tự động gia hạn gói dịch vụ, thanh toán đơn hàng, thanh toán chi phí định kỳ, ... của khách hàng.
Các bước tích hợp Auto Debit
Dưới đây là các bước để tích hợp Thu phí tự động vào sản phẩm của bạn.
-
Tạo một phân quyền /grant/token với
scopescó giá trị làauto_debit. -
Mở giao diện Cas Link bằng
grantTokenđược trả về ở bước trên. Xem chi tiết -
Sau khi người dùng hoàn tất xác thực, phía giao diện của bạn sẽ nhận được một publicToken, dùng publicToken này để lấy accessToken cho phân quyền.
-
Sau khi có
accessToken, gọi API lấy thông tin tài khoản dịch vụ thu hộ tự động để kiểm tra thông tin. -
Gọi API Thu phí tự động để thực hiện tạo lệnh trích nợ tự động cho Gia hạn gói dịch vụ của khách hàng, thanh toán đơn hàng, ...
-
Khi một giao dịch Thu phí tự động (Trích nợ tự động) được xử lý thành công hoặc thật bại, phía hệ thống Cas sẽ gửi một webhook kèm thông tin ở trường
autoDebit, hệ thống của bạn khi nhận được thông tin này cần kiểm tra lại thông tin thanh toán và tiếp tục xử lý các bước tiếp theo.
Gọi API
Tạo phân quyền cho 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);
});
Xem chi tiết API, tại đây
Lấy accessToken từ 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);
});
Xem chi tiết API, tại đây
Lấy thông tin định danh của TK thanh toán tự động
- 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);
});
Xem chi tiết API, tại đây
Tạo lệnh Thanh toán tự động
- 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);
});
Xem chi tiết API, tại đây