> For the complete documentation index, see [llms.txt](https://doc.vietqr.vn/doc/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://doc.vietqr.vn/doc/api-vietqr-callback/tai-lieu-ket-noi-vietqr.md).

# Tài liệu kết nối VietQR

Mở Tài khoản VIetQR VN & Tự động khai báo kết nối Test

<figure><img src="/files/nVwqExN5cOGHQccyQKKk" alt=""><figcaption></figcaption></figure>

API Nhận biến động số dư

\- Request mẫu

```
// Some code
curl --location –request
POST 'https://api-agency.trueconnect.vn/payment/VietQR/tanviet/transaction-sync' \
--header 'Content-Type: application/json' \
--data-raw '{
  "transactionId": "0a4cc317-3af3-4055-bc83-7296adb624bf",
  "transactionTime": "2024-05-1701:53",
  "referencenumber": "0a4cc317-3af3-4055-bc83-7296adb624bf",
  "amount": "100000",
  "content": "Chuyenkhoan",
  "bankAccount": "0362626234",
  "transType": "C",
  "orderId":"0a4cc317-3af3-4055-bc83-7296adb624bf",
  "signature": "241fad517529e1abfef81756f615a6edd0a765846f0e926563ee88540c4a9ef1"
}'

```

Trong đó:

| <p>transactionId</p><p> </p>   | ID của giao dịch                          | string | 36 kí tự            |
| ------------------------------ | ----------------------------------------- | ------ | ------------------- |
| <p>transactionTime</p><p> </p> | Thời gian ghi nhận giao dịch              | string |                     |
| <p>referencenumber</p><p> </p> | Mã reference number của ngân hàng trả về. | string |                     |
| <p>amount</p><p> </p>          | Số tiền                                   | string | <= 10 kí tự         |
| <p>content</p><p> </p>         | Nội dung chuyển khoản                     | string | Viết liền không dấu |
| bankAccount                    | Số tài khoản ngân hàng                    | string | 8-15 kí tự          |
| transType                      | Giao dịch ghi nợ/có (giá trị: D/C)        | string |                     |
| orderId                        | Mã hoá đơn của khách hàng                 | string | 36 kí tự            |
| signature                      | Token (Cách tạo ở mục 2)                  | string |                     |

Response:

```
{
    "error": false,
    "errorReason": "000",
    "toastMessage": "0a4cc317-3af3-4055-bc83-7296adb624bf",
    "messageError": "Success"
}

```

Trong đó:

| error        | Có lỗi hay không (true: có, false: không)        |
| ------------ | ------------------------------------------------ |
| errorReason  | Mã lỗi: 001- agency không tồn tại, 002- lỗi khác |
| toastMessage | ID giao dịch                                     |
| messageError | Nội dung lỗi                                     |

1\.    Cách tạo signature

Secret: “YWN0aXZlX3NpZ24ga2V5LiBLZWVwIGl0IHNlY3JldCE=”

&#x20;    Gồm 2 thành phần là data và secret

&#x20;    Data dạng chuỗi

&#x20;      “ 0a4cc317-3af3-4055-bc83-7296adb624bf00001000002024-05-1701:530a4cc317-3af3-4055-bc83-7296adb624bf ”

&#x20;      Mô tả: chuỗi dạng

&#x20;    $“{transactionId}{Giá tiền dạng 10 chữ số}{transactionTime}{orderId}”

&#x20;    Ví dụ: với request mẫu ở mục 1

| <p>    transactionId = 0a4cc317-3af3-4055-bc83-7296adb624bf</p><p>    amount = 0000100000</p><p>    transactionTime = 2024-05-1701:53</p><p>    orderId = 0a4cc317-3af3-4055-bc83-7296adb624bf</p> |
| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |

B1: Chuyển đổi chuỗi data và secret thành mảng byte sử dụng mã hóa UTF-8.

B2: Sử dụng mảng byte của secret như là khóa để tạo một đối tượng HMACSHA256 , một loại mã hóa được sử dụng để tạo giá trị băm (hash) với thuật toán SHA-256.

B3: Tính toán giá trị băm của mảng byte sinh từ data. Kết quả thu được là một mảng byte

B4: Duyệt qua từng mảng byte và chuyển đổi từng phần tử thành 1 chuỗi hex ghép lại thành signature cần tạo

Code mẫu .net

```
public static string HmacSha256Digest(string data, string secret)
  {
      if (string.IsNullOrEmpty(data)) return string.Empty;
      UTF8Encoding encoding = new();
      byte[] keyBytes = encoding.GetBytes(secret);
      byte[] messageBytes = encoding.GetBytes(data);
      HMACSHA256 cryptographer = new(keyBytes);

      byte[] bytes = cryptographer.ComputeHash(messageBytes);
      return bytes.ToHex();
  } 

```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://doc.vietqr.vn/doc/api-vietqr-callback/tai-lieu-ket-noi-vietqr.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
