Sử dụng API Casso Danh sách API 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 đã 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 đâ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.
Tạo webhook
POST
https://oauth.casso.vn/v2/webhooks
Thực hiện tạo webhook tới server của bạn
Bearer <"access token từ OAuth2">
hoặc Apikey <"API key của bạn">
Request Body
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
Mã bảo mật để mỗi lần gửi Event từ Casso sẽ được đính kèm trên header.
Đường dẫn(endpoint/API) nhận event(phát sinh giao dịch mới) từ Casso
200 Response thông tin webhook đã tạo thành công. 401 Access-Token không đúng hoặc đã hết hạn.
Copy {
"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
}
}
Copy {
"error": 401,
"message": "Unauthorized Access",
"data": null
}
Ví dụ:
CURL PHP JAVA
Copy curl --location --request POST 'https://oauth.casso.vn/v2/webhooks' \
--header 'Authorization: Apikey <"API Key của bạn"> hoặc Bearer <"access token từ OAuth2">' \
--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
}'
Copy $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://oauth.casso.vn/v2/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: Apikey <"API Key của bạn"> Hoặc Bearer <"access token từ OAuth2">",
"Content-Type: application/json"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
Copy 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://oauth.casso.vn/v2/webhooks")
.post(formBody)
.addHeader("Content-Type", "application/json")
.addHeader("Authorization", "Apikey <"API Key của bạn"> hoặc Bearer <"access token từ OAuth2">")
.build();
Response response = client.newCall(request).execute();
Xem chi tiết webhook
GET
https://oauth.casso.vn/v2/webhooks/:id
Xem chi tiết các thông về webhook của bạn theo dựa theo webhook Id
Path Parameters
id webhook
bạn muốn xem chi tiết
Bearer <"access token từ Oauth2">
hoặc Apikey <"API key của bạn">
200 401
Copy {
"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
}
}
Copy {
"error": 401,
"message": "Unauthorized Access",
"data": null
}
Ví dụ:
CURL PHP JAVA
Copy curl --location --request GET 'https://oauth.casso.vn/v2/webhooks/134' \
--header 'Authorization: Bearer <"Access token nhận được từ OAuth 2.0 của Casso">'
Copy $curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://oauth.casso.vn/v2/webhooks/134",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"Authorization: Apikey <"API Key của bạn"> hoặc Bearer <"access token từ OAuth2">",
"Content-Type: application/json"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
Copy OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder()
.url("https://oauth.casso.vn/v2/webhooks/134")
.get()
.addHeader("Content-Type", "application/json")
.addHeader("Authorization", "Apikey <"API Key của bạn"> hoặc Bearer <"access token từ OAuth2">")
.build();
Response response = client.newCall(request).execute();
Cập nhật một webhook
PUT
https://oauth.casso.vn/v2/webhooks/:id
Cập nhật các thông tin trong webhook đã được thiết lập trước đó
Path Parameters
Bearer <"access token từ OAuth2">
hoặc Apikey <"API key của bạn">
Request Body
Xác nhận gửi webhook đối với tiền vào
Đường dẫn(endpoint/API) nhận event(phát sinh giao dịch mới) từ Casso
200 401
Copy {
"error": 0,
"message": "success",
"data": {
"id": 111,
"channel": "webhook",
"param1": "https://webhook-cua-ban.com.vn",
"param2": "sdf",
"send_only_income": 1
}
}
Copy {
"error": 401,
"message": "Unauthorized Access",
"data": null
}
Ví dụ:
CURL PHP JAVA
Copy curl --location --request PUT 'https://oauth.casso.vn/v2/webhooks/111' \
--header 'Authorization: Apikey <"API Key của bạn"> Hoặc Bearer <"access token từ OAuth2">' \
--header 'Content-Type: application/json' \
--data-raw '{
"webhook": "https://ten-mien-cua-ban.com/api/bank",
"secure_token": "@xyz@123",
"income_only": "false"
}'
Copy $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://oauth.casso.vn/v2/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: Apikey <"API Key của bạn"> Hoặc Bearer <"access token từ OAuth2">",
"Content-Type: application/json"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
Copy 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://oauth.casso.vn/v2/webhooks/111")
.post(formBody)
.addHeader("Content-Type", "application/json")
.addHeader("Authorization", "Apikey <"API Key của bạn"> hoặc Bearer <"access token từ OAuth2">")
.build();
Response response = client.newCall(request).execute();
Xoá một webhook
DELETE
https://oauth.casso.vn/v2/webhooks/:id
Thực hiện xóa một webhook bằng id webhook
Path Parameters
Bearer <"access token từ OAuth2">
hoặc Apikey <"API key của bạn">
200 401
Copy {
"error": 0,
"message": "success",
"data": {
"id": 111,
"channel": "webhook",
"param1": "https://khanh-dep-trai.com.vn",
"param2": "sdf",
"send_only_income": 1
}
}
Copy {
"error": 401,
"message": "Unauthorized Access",
"data": null
}
Ví dụ:
CURL PHP JAVA
Copy curl --location --request DELETE 'https://oauth.casso.vn/v2/webhooks/85' \
--header 'Authorization: Bearer <"Access token nhận được từ OAuth 2.0 của Casso">'
Copy $curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://oauth.casso.vn/v2/webhooks/85",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 30,
CURLOPT_CUSTOMREQUEST => "DELETE",
CURLOPT_HTTPHEADER => array(
"Authorization: Apikey <"API Key của bạn"> hoặc Bearer <"access token từ OAuth2">",
"Content-Type: application/json"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
Copy OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder()
.url("https://oauth.casso.vn/v2/webhooks/85")
.delete()
.addHeader("Content-Type", "application/json")
.addHeader("Authorization", "Apikey <"API Key của bạn"> hoặc Bearer <"access token từ OAuth2">")
.build();
Response response = client.newCall(request).execute();
Xoá tất cả webhook trong đường dẫn
DELETE
https://oauth.casso.vn/v2/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 tương ứng với giá trị webhook mà bạn yêu cầu.
Query Parameters
Đường dẫn(endpoint/API) nhận event(phát sinh giao dịch mới) từ Casso
Bearer <"access token từ OAuth2">
hoặc Apikey <"API key của bạn">
200 401 404
Copy {
"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
},
]
}
Copy {
"error": 401,
"message": "Unauthorized Access",
"data": null
}
Copy {
"error": 12,
"message": "Webhook not exists",
"data": null
}
Ví dụ:
CURL PHP JAVA
Copy curl --location --request DELETE 'https://oauth.casso.vn/v2/webhooks?webhook=https://websitecuaban.com/api/webhook' \
--header 'Authorization: Bearer <"Access token nhận được từ OAuth 2.0 của Casso">'
Copy $curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://oauth.casso.vn/v2/webhooks?webhook=https://websitecuaban.com/api/webhook",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 30,
CURLOPT_CUSTOMREQUEST => "DELETE",
CURLOPT_HTTPHEADER => array(
"Authorization: Apikey <"API Key của bạn"> hoặc Bearer <"access token từ OAuth2">",
"Content-Type: application/json"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
Copy OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder()
.url("https://oauth.casso.vn/v2/webhooks?webhook=https://websitecuaban.com/api/webhook")
.delete()
.addHeader("Content-Type", "application/json")
.addHeader("Authorization", "Apikey <"API Key của bạn"> hoặc Bearer <"access token từ OAuth2">")
.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 hệ thống của Casso. Cân nhắc trước khi dùng tới API này.