# API Lấy cấu hình Merchant

- Anchor: `bankhub-vi-api-api-merchant-thong-tin-cau-hinh`
- URL: https://developer.sepay.vn/vi/bankhub/api/api-merchant/thong-tin-cau-hinh.md
- Description: API lấy cấu hình hiện tại của merchant bao gồm transaction whitelist keywords, custom CSS và logo URL.

#### API Endpoint

**GET** `https://bankhub-api-sandbox.sepay.vn/v1/merchant-config`

API lấy thông tin cấu hình merchant hiện tại.

**Authentication:** bearerAuth

> **Lưu ý** (info)
> - API này yêu cầu Bearer Token trong header Authorization
> - Trả về cấu hình hiện tại của merchant
> - Nếu merchant chưa có cấu hình, các trường sẽ có giá trị mặc định (array rỗng hoặc null)
> - Custom CSS được áp dụng cho tất cả hosted link của merchant

#### 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/merchant-config \
  --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/merchant-config",
  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/merchant-config", 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/merchant-config",
  "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/merchant-config")
  .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/merchant-config")

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/merchant-config"

	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/merchant-config"),
    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/merchant-config")! 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/merchant-config")
  .get()
  .addHeader("Authorization", "Bearer REPLACE_BEARER_TOKEN")
  .build()

val response = client.newCall(request).execute()
```

---

### Ví dụ sử dụng

---

> **Transaction Whitelist Keywords** (info)
> **Cách hoạt động:**
> - Danh sách từ khóa dùng để lọc giao dịch trước khi gửi webhook
> - Chỉ giao dịch có nội dung (`transaction_content`) chứa ít nhất một từ khóa mới được gửi webhook
> - Không phân biệt hoa thường khi so khớp
> - Nếu mảng rỗng `[]`, tất cả giao dịch đều được gửi webhook
>
> **Ví dụ:**
> - Keywords: `["thanh toan", "payment"]`
> - Transaction content: "Chuyen khoan thanh toan don hang ABC" → **Được gửi webhook**
> - Transaction content: "Gui tien cho ban" → **Không gửi webhook**

> **Global Hosted Link Custom CSS** (info)
> **Custom CSS cho WebView:**
> - CSS được inject vào tất cả hosted link của merchant
> - Cho phép tùy chỉnh màu sắc, font chữ, layout của giao diện WebView
> - Phải là CSS hợp lệ, không chứa script hoặc mã độc
>
> **Lưu ý:**
> - CSS không được phá vỡ functionality của hosted link
> - Nên test kỹ trước khi deploy lên production

> **Lưu ý quan trọng** (warn)
> - Thay đổi cấu hình ảnh hưởng ngay lập tức đến tất cả hosted link đang active
> - Custom CSS cần tuân thủ security policy (không chứa script, external resource)
> - Whitelist keywords nên được cập nhật cẩn thận để tránh miss webhook quan trọng

---
