Casso Developer
stable (v2)
stable (v2)
  • Tổng quan
  • Kết nối Casso bằng Webhook
    • Thiết lập Webhook thủ công
    • Xử lý sự kiện Webhook
  • Sử dụng API Casso
    • Chứng thực API
      • Tạo API Key thủ công
    • Danh sách API
      • API lấy thông tin user
      • API thiết lập webhook
      • API lấy giao dịch
      • API lấy thông tin tài khoản ngân hàng
      • API buộc đồng bộ giao dịch mới ngay
  • Tài nguyên khác
    • Tích hợp xác nhận thanh toán
    • Change log
Powered by GitBook
On this page
  • Trước khi bắt đầu
  • Tạo webhook
  • Xem chi tiết webhook
  • Cập nhật một webhook
  • Xoá một webhook
  • Xoá tất cả webhook trong đường dẫn

Was this helpful?

  1. Sử dụng API Casso
  2. 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.

PreviousAPI lấy thông tin userNextAPI lấy giao dịch

Last updated 1 year ago

Was this helpful?

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 đã 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à .

  • Endpoint/API này phải public ra ngoài Internet. Nếu như bạn đang ở local bạn có thể để biết cách public endpoint của bạn.

  • Bạn cần có để thiết lập ở trường Authorization HTTP Header.

Tạo webhook

POST https://oauth.casso.vn/v2/webhooks

Thực hiện tạo webhook tới server của bạn

Headers

Name
Type
Description

Authorization

string

Bearer <"access token từ OAuth2"> hoặc Apikey <"API key của bạn">

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 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

{
    "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
    }
}
{
    "error": 401,
    "message": "Unauthorized Access",
    "data": null
}

Ví dụ:

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();

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

Name
Type
Description

id

string

id webhook bạn muốn xem chi tiết

Headers

Name
Type
Description

Authorization

string

Bearer <"access token từ Oauth2"> hoặc Apikey <"API key của bạn">

{
    "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
    }
}
{
    "error": 401,
    "message": "Unauthorized Access",
    "data": null
}

Ví dụ:

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();

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

Name
Type
Description

id

string

id webhook

Headers

Name
Type
Description

Authorization

string

Bearer <"access token từ OAuth2"> hoặc Apikey <"API key của bạn">

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

{
    "error": 0,
    "message": "success",
    "data": {
        "id": 111,
        "channel": "webhook",
        "param1": "https://webhook-cua-ban.com.vn",
        "param2": "sdf",
        "send_only_income": 1
    }
}
{
    "error": 401,
    "message": "Unauthorized Access",
    "data": null
}

Ví dụ:

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();

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

Name
Type
Description

id

string

id webhook

Headers

Name
Type
Description

Authorization

string

Bearer <"access token từ OAuth2"> hoặc Apikey <"API key của bạn">

{
    "error": 0,
    "message": "success",
    "data": {
        "id": 111,
        "channel": "webhook",
        "param1": "https://khanh-dep-trai.com.vn",
        "param2": "sdf",
        "send_only_income": 1
    }
}
{
    "error": 401,
    "message": "Unauthorized Access",
    "data": null
}

Ví dụ:

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();

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

Name
Type
Description

webhook

string

Đường dẫn(endpoint/API) nhận event(phát sinh giao dịch mới) từ Casso

Headers

Name
Type
Description

Authorization

string

Bearer <"access token từ OAuth2"> hoặc Apikey <"API key của bạn">

{
    "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
        },
    ]
}
{
    "error": 401,
    "message": "Unauthorized Access",
    "data": null
}
{
    "error": 12,
    "message": "Webhook not exists",
    "data": null
}

Ví dụ:

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.

Casso
Webhook
API Key
xem hương dẫn này