API thiết lập webhook
Dùng để thiết lập webhook như: thêm, sửa và xóa.
Trước khi bắt đầu
Một số lưu ý trước khi bắt đầu với các API liên quan tới webhook:
- Một tài khoản Casso Flow đã liên kết một tài khoản ngân hàng. Để test với API này có thể sử dụng tài khoản demo.
- Bạn cần có một endpoint/API để nhận sự kiện từ Casso Flow đây được gọi là Webhook.
- Endpoint/API này phải public ra ngoài Internet. Nếu như bạn đang ở local bạn có thể xem hương dẫn này để biết cách public endpoint của bạn.
- Bạn cần có access token để gửi trong trường Authorization.
Tạo webhook
POST https://openapi.casso.vn/flow/v3/webhooks
Thực hiện tạo webhook tới server của bạn
Headers
| Name | Type | Description |
|---|---|---|
| Authorization | string | Bearer <access_token> |
Request Body
| Name | Type | Description |
|---|---|---|
| income_only | boolean | Giá trị được thiết lập để gửi bắn sự kiện tới webhook đối với giao dịch tiền vào |
| secure_token | string | Mã bảo mật để mỗi lần gửi Event từ Casso Flow sẽ được đính kèm trên header. |
| webhook | string | Đường dẫn(endpoint/API) nhận event(phát sinh giao dịch mới) từ Casso Flow |
200 Response thông tin webhook đã tạo thành công.
{
"error": 0,
"message": "success",
"data": {
"id": 114,
"channel": "webhook",
"param1": "https://ten-mien-cua-ban.com/wc/handler-bank-transfer.php",
"param2": "",
"send_only_income": 1
}
}
401 Access-Token không đúng hoặc đã hết hạn.
{
"error": 401,
"message": "Unauthorized Access",
"data": null
}
Ví dụ:
CURL
curl --location --request POST 'https://openapi.casso.vn/flow/v3/webhooks' \
--header 'Authorization: Bearer <access_token>' \
--header 'Content-Type: application/json' \
--data-raw '{
"webhook": "https://ten-mien-cua-ban.com/wc/handler-bank-transfer.php",
"secure_token": "@123#abc",
"income_only": true
}'
PHP
$curl = curl_init();
$data = array(
'webhook' => 'https://ten-mien-cua-ban.com/wc/handler-bank-transfer.php',
'secure_token' => '@123#abc',
'income_only' => true
);
$postdata = json_encode($data);
curl_setopt_array($curl, array(
CURLOPT_URL => "https://openapi.casso.vn/flow/v3/webhooks",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => $postdata),
CURLOPT_HTTPHEADER => array(
"Authorization: Bearer <access_token>",
"Content-Type: application/json"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
JAVA
OkHttpClient client = new OkHttpClient();
RequestBody formBody = new FormBody.Builder()
.add("webhook", "https://ten-mien-cua-ban.com/wc/handler-bank-transfer.php")
.add("secure_token", "@123#abc")
.add("income_only", true)
.build();
Request request = new Request.Builder()
.url("https://openapi.casso.vn/flow/v3/webhooks")
.post(formBody)
.addHeader("Content-Type", "application/json")
.addHeader("Authorization", "Bearer <access_token>")
.build();
Response response = client.newCall(request).execute();
Xem chi tiết webhook
GET https://openapi.casso.vn/flow/v3/webhooks/:id
Xem chi tiết các thông về webhook của bạn theo dựa theo webhook Id
Path Parameters
| Name | Type | Description |
|---|---|---|
| id | string | id webhook bạn muốn xem chi tiết |
Headers
| Name | Type | Description |
|---|---|---|
| Authorization | string | Bearer <access_token> |
200
{
"error": 0,
"message": "success",
"data": {
"id": 111,
"channel": "webhook",
"param1": "https://ten-mien-cua-ban.com.vn/wc/handler-bank-transfer.php",
"param2": "",
"send_only_income": 1
}
}
401
{
"error": 401,
"message": "Unauthorized Access",
"data": null
}
Ví dụ:
CURL
curl --location --request GET 'https://openapi.casso.vn/flow/v3/webhooks/134' \
--header 'Authorization: Bearer <access_token>'
PHP
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://openapi.casso.vn/flow/v3/webhooks/134",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"Authorization: Bearer <access_token>",
"Content-Type: application/json"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
JAVA
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder()
.url("https://openapi.casso.vn/flow/v3/webhooks/134")
.get()
.addHeader("Content-Type", "application/json")
.addHeader("Authorization", "Bearer <access_token>")
.build();
Response response = client.newCall(request).execute();
Cập nhật một webhook
PUT https://openapi.casso.vn/flow/v3/webhooks/:id
Cập nhật các thông tin trong webhook đã được thiết lập trước đó
Path Parameters
| Name | Type | Description |
|---|---|---|
| id | string | id webhook |
Headers
| Name | Type | Description |
|---|---|---|
| Authorization | string | Bearer <access_token> |
Request Body
| Name | Type | Description |
|---|---|---|
| income_only | boolean | Xác nhận gửi webhook đối với tiền vào |
| secure_token | string | mã bảo mật |
| webhook | string | Đường dẫn(endpoint/API) nhận event(phát sinh giao dịch mới) từ Casso Flow |
200
{
"error": 0,
"message": "success",
"data": {
"id": 111,
"channel": "webhook",
"param1": "https://webhook-cua-ban.com.vn",
"param2": "sdf",
"send_only_income": 1
}
}
401
{
"error": 401,
"message": "Unauthorized Access",
"data": null
}
Ví dụ:
CURL
curl --location --request PUT 'https://openapi.casso.vn/flow/v3/webhooks/111' \
--header 'Authorization: Bearer <access_token>' \
--header 'Content-Type: application/json' \
--data-raw '{
"webhook": "https://ten-mien-cua-ban.com/api/bank",
"secure_token": "@xyz@123",
"income_only": "false"
}'
PHP
$curl = curl_init();
$data = array(
'webhook' => 'https://ten-mien-cua-ban.com/api/bank'
);
$postdata = json_encode($data);
curl_setopt_array($curl, array(
CURLOPT_URL => "https://openapi.casso.vn/flow/v3/webhooks/111",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PUT",
CURLOPT_POSTFIELDS => $postdata),
CURLOPT_HTTPHEADER => array(
"Authorization: Bearer <access_token>",
"Content-Type: application/json"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
JAVA
OkHttpClient client = new OkHttpClient();
RequestBody formBody = new FormBody.Builder()
.add("webhook", "https://ten-mien-cua-ban-new.com/wc-new/handler-bank-transfer.php")
.add("secure_token", "@123#abc-new")
.build();
Request request = new Request.Builder()
.url("https://openapi.casso.vn/flow/v3/webhooks/111")
.post(formBody)
.addHeader("Content-Type", "application/json")
.addHeader("Authorization", "Bearer <access_token>")
.build();
Response response = client.newCall(request).execute();
Xoá một webhook
DELETE https://openapi.casso.vn/flow/v3/webhooks/:id
Thực hiện xóa một webhook bằng id webhook
Path Parameters
| Name | Type | Description |
|---|---|---|
| id | string | id webhook |
Headers
| Name | Type | Description |
|---|---|---|
| Authorization | string | Bearer <access_token> |
200
{
"error": 0,
"message": "success",
"data": {
"id": 111,
"channel": "webhook",
"param1": "https://khanh-dep-trai.com.vn",
"param2": "sdf",
"send_only_income": 1
}
}
401
{
"error": 401,
"message": "Unauthorized Access",
"data": null
}
Ví dụ:
CURL
curl --location --request DELETE 'https://openapi.casso.vn/flow/v3/webhooks/85' \
--header 'Authorization: Bearer <access_token>'
PHP
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://openapi.casso.vn/flow/v3/webhooks/85",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 30,
CURLOPT_CUSTOMREQUEST => "DELETE",
CURLOPT_HTTPHEADER => array(
"Authorization: Bearer <access_token>",
"Content-Type: application/json"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
JAVA
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder()
.url("https://openapi.casso.vn/flow/v3/webhooks/85")
.delete()
.addHeader("Content-Type", "application/json")
.addHeader("Authorization", "Bearer <access_token>")
.build();
Response response = client.newCall(request).execute();
Xoá tất cả webhook trong đường dẫn
DELETE https://openapi.casso.vn/flow/v3/webhooks
Xóa tất cả các webhook đang tồn tại trong doanh nghiệp của bạn trên Casso Flow tương ứng với giá trị webhook mà bạn yêu cầu.
Query Parameters
| Name | Type | Description |
|---|---|---|
| webhook | string | Đường dẫn(endpoint/API) nhận event(phát sinh giao dịch mới) từ Casso Flow |
Headers
| Name | Type | Description |
|---|---|---|
| Authorization | string | Bearer <access_token> |
200
{
"error": 0,
"message": "success",
"data": [
{
"id": 108,
"channel": "webhook",
"param1": "https://ten-mien-cua-ban.com/wc/handler.php",
"param2": "",
"send_only_income": 1
},
{
"id": 109,
"channel": "webhook",
"param1": "https://ten-mien-cua-ban.com/wc/handler.php",
"param2": "",
"send_only_income": 1
},
{
"id": 110,
"channel": "webhook",
"param1": "https://ten-mien-cua-ban.com/wc/handler.php",
"param2": "",
"send_only_income": 1
},
]
}
401
{
"error": 401,
"message": "Unauthorized Access",
"data": null
}
404
{
"error": 12,
"message": "Webhook not exists",
"data": null
}
Ví dụ:
CURL
curl --location --request DELETE 'https://openapi.casso.vn/flow/v3/webhooks?webhook=https://websitecuaban.com/api/webhook' \
--header 'Authorization: Bearer <access_token>'
PHP
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://openapi.casso.vn/flow/v3/webhooks?webhook=https://websitecuaban.com/api/webhook",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 30,
CURLOPT_CUSTOMREQUEST => "DELETE",
CURLOPT_HTTPHEADER => array(
"Authorization: Bearer <access_token>",
"Content-Type: application/json"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
JAVA
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder()
.url("https://openapi.casso.vn/flow/v3/webhooks?webhook=https://websitecuaban.com/api/webhook")
.delete()
.addHeader("Content-Type", "application/json")
.addHeader("Authorization", "Bearer <access_token>")
.build();
Response response = client.newCall(request).execute();
Lưu ý: Khi bạn gọi API có thể sẽ xóa đi những webhook cũ mà bạn đã thiết lập trên Casso Flow. Cân nhắc trước khi dùng tới API này.