Comment on page
API thiết lập webhook
Dùng để thiết lập webhook như: thêm, sửa và xóa.
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.
- 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ó API Key hoặc Access token từ Oauth 2.0 của Casso để thiết lập ở trường Authorization HTTP Header.
post
https://oauth.casso.vn
/v2/webhooks
Tạo webhook
CURL
PHP
JAVA
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
}'
$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);
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();
get
https://oauth.casso.vn
/v2/webhooks/:id
Xem chi tiết webhook
CURL
PHP
JAVA
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">'
$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);
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();
put
https://oauth.casso.vn/
v2/webhooks/:id
Cập nhật một webhook
CURL
PHP
JAVA
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"
}'
$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);
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();
delete
https://oauth.casso.vn
/v2/webhooks/:id
Xoá một webhook
CURL
PHP
JAVA
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">'
$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);
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();
delete
https://oauth.casso.vn
/v2/webhooks
Xoá tất cả webhook trong đường dẫn
CURL
PHP
JAVA
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">'
$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);
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.
Last modified 2yr ago