# API Lấy cấu hình Webhook

- Anchor: `bankhub-vi-api-api-webhook-thong-tin-webhook`
- URL: https://developer.sepay.vn/vi/bankhub/api/api-webhook/thong-tin-webhook.md
- Description: API lấy cấu hình webhook hiện tại của merchant. Webhook được dùng để nhận thông báo sự kiện từ Bank Hub.

#### API Endpoint

**GET** `https://bankhub-api-sandbox.sepay.vn/v1/webhook`

Lấy thông tin cấu hình webhook hiện tại của merchant.

**Lưu ý:**
- Nếu chưa cấu hình webhook, trả về `data: null`
- Secret key được che (hiển thị 4 ký tự cuối): `***5678`

**Authentication:** bearerAuth

> **Lưu ý** (info)
> - API này yêu cầu Bearer Token trong header Authorization
> - Trả về cấu hình webhook hiện tại của merchant
> - Nếu chưa cấu hình webhook, trả về `data: null`
> - Secret key được che (hiển thị 4 ký tự cuối)

#### Xử lý lỗi

#### API Response

**Response 200:** Thành công

**Response 401:** 

#### Code mẫu

**cURL:**
```bash
curl --request GET \
  --url https://bankhub-api-sandbox.sepay.vn/v1/webhook \
  --header 'Authorization: Bearer REPLACE_BEARER_TOKEN'
```

**PHP:**
```php
<?php

$curl = curl_init();

curl_setopt_array($curl, [
  CURLOPT_URL => "https://bankhub-api-sandbox.sepay.vn/v1/webhook",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_HTTPHEADER => [
    "Authorization: Bearer REPLACE_BEARER_TOKEN"
  ],
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}
```

**Python:**
```python
import http.client

conn = http.client.HTTPSConnection("bankhub-api-sandbox.sepay.vn")

headers = { 'Authorization': "Bearer REPLACE_BEARER_TOKEN" }

conn.request("GET", "/v1/webhook", headers=headers)

res = conn.getresponse()
data = res.read()

print(data.decode("utf-8"))
```

**NodeJS:**
```javascript
const http = require("https");

const options = {
  "method": "GET",
  "hostname": "bankhub-api-sandbox.sepay.vn",
  "port": null,
  "path": "/v1/webhook",
  "headers": {
    "Authorization": "Bearer REPLACE_BEARER_TOKEN"
  }
};

const req = http.request(options, function (res) {
  const chunks = [];

  res.on("data", function (chunk) {
    chunks.push(chunk);
  });

  res.on("end", function () {
    const body = Buffer.concat(chunks);
    console.log(body.toString());
  });
});

req.end();
```

**Java:**
```java
OkHttpClient client = new OkHttpClient();

Request request = new Request.Builder()
  .url("https://bankhub-api-sandbox.sepay.vn/v1/webhook")
  .get()
  .addHeader("Authorization", "Bearer REPLACE_BEARER_TOKEN")
  .build();

Response response = client.newCall(request).execute();
```

**Ruby:**
```ruby
require 'uri'
require 'net/http'
require 'openssl'

url = URI("https://bankhub-api-sandbox.sepay.vn/v1/webhook")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE

request = Net::HTTP::Get.new(url)
request["Authorization"] = 'Bearer REPLACE_BEARER_TOKEN'

response = http.request(request)
puts response.read_body
```

**Go:**
```go
package main

import (
	"fmt"
	"net/http"
	"io/ioutil"
)

func main() {

	url := "https://bankhub-api-sandbox.sepay.vn/v1/webhook"

	req, _ := http.NewRequest("GET", url, nil)

	req.Header.Add("Authorization", "Bearer REPLACE_BEARER_TOKEN")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := ioutil.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

**.NET:**
```csharp
var client = new HttpClient();
var request = new HttpRequestMessage
{
    Method = HttpMethod.Get,
    RequestUri = new Uri("https://bankhub-api-sandbox.sepay.vn/v1/webhook"),
    Headers =
    {
        { "Authorization", "Bearer REPLACE_BEARER_TOKEN" },
    },
};
using (var response = await client.SendAsync(request))
{
    response.EnsureSuccessStatusCode();
    var body = await response.Content.ReadAsStringAsync();
    Console.WriteLine(body);
}
```

**Swift:**
```swift
import Foundation

let headers = ["Authorization": "Bearer REPLACE_BEARER_TOKEN"]

let request = NSMutableURLRequest(url: NSURL(string: "https://bankhub-api-sandbox.sepay.vn/v1/webhook")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "GET"
request.allHTTPHeaderFields = headers

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```

**Kotlin:**
```kotlin
val client = OkHttpClient()

val request = Request.Builder()
  .url("https://bankhub-api-sandbox.sepay.vn/v1/webhook")
  .get()
  .addHeader("Authorization", "Bearer REPLACE_BEARER_TOKEN")
  .build()

val response = client.newCall(request).execute()
```

---

### Ví dụ sử dụng

---

> **Allow Events Configuration** (info)
> **Cách hoạt động:**
> - `null` hoặc `[]`: Không gửi bất kỳ sự kiện nào
> - `["*"]`: Gửi tất cả 13 loại sự kiện
> - `["BANK_ACCOUNT_LINKED", "BANK_ACCOUNT_UNLINKED"]`: Chỉ gửi các sự kiện cụ thể
>
> **13 loại sự kiện:**
> - Link Token: `LINK_TOKEN_CREATED`, `LINK_TOKEN_REVOKED`, `LINK_TOKEN_EXPIRED`
> - Link Session: `LINK_SESSION_INITIALIZED`, `LINK_SESSION_REINITIALIZED`, `LINK_SESSION_STATE_CHANGED`, `LINK_SESSION_COMPLETED`, `LINK_SESSION_FAILED`, `LINK_SESSION_ABANDONED`, `LINK_SESSION_EXPIRED`
> - Bank Account: `BANK_ACCOUNT_LINKED`, `BANK_ACCOUNT_UNLINKED`, `BANK_ACCOUNT_INACTIVATED`

> **Secret Key Display** (info)
> - Trong GET response, secret key được che để bảo mật
> - Chỉ hiển thị 4 ký tự cuối: `***5678`
> - Secret key đầy đủ chỉ trả về khi tạo/cập nhật qua POST

> **Lưu ý quan trọng** (warn)
> - Nếu `data` là `null`, merchant chưa cấu hình webhook
> - Secret key được mask trong GET response (hiển thị `***xxxx`)
> - `allow_events = null` hoặc `[]` nghĩa là webhook sẽ không gửi bất kỳ event nào
> - Active = 0 nghĩa là webhook bị tắt, không gửi event dù có cấu hình `allow_events`

---
