> For the complete documentation index, see [llms.txt](https://just-trade.gitbook.io/just-trade-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://just-trade.gitbook.io/just-trade-docs/obshaya-informaciya/vebkhuki.md).

# Вебхуки

API поддерживает вебхуки для уведомлений об изменении статуса счетов (например, invoice\_paid). Если вебхук настроен в настройках приложения, система отправляет POST-запрос на указанный URL.

## Формат вебхука

**Метод**: POST\
**Заголовки**:

* Content-Type: application/json

**Тело запроса**:

```json
{
  "invoice_id": "app_invoice_1a2b3c4d5e6f7890",
  "amount": 0.01,
  "payer": "123456",
  "currency": "BTC",
  "custom_data": { "order_id": "123" },
  "secret_hash": "a1b2c3d4e5f6..."
}
```

**Поля**:

| Поле         | Тип    | Описание                                                             |
| ------------ | ------ | -------------------------------------------------------------------- |
| invoice\_id  | string | Уникальный ID счета.                                                 |
| amount       | float  | Сумма счета.                                                         |
| payer        | string | ID пользователя, выполнившего оплату.                                |
| currency     | string | Код валюты оплаты (например, BTC или USD).                           |
| custom\_data | object | Дополнительные данные, указанные в webhook\_data при создании счета. |
| secret\_hash | string | Хэш подписи для проверки подлинности вебхука.                        |

## Проверка подписи (secret\_hash)

Каждый вебхук включает поле secret\_hash, которое создаётся с использованием токена API вашего приложения. Для проверки подлинности:

1. Получите токен API приложения (выданный при регистрации).
2. Сформируйте строку из полей вебхука: invoice\_id, amount, payer, currency, custom\_data (в виде строки JSON).
3. Создайте HMAC-SHA256 подпись, используя токен API как ключ.
4. Сравните полученный хэш с secret\_hash из вебхука.

**Пример проверки подписи (Node.js)**:

```javascript
const crypto = require('crypto');

const webhookPayload = {
  invoice_id: "app_invoice_1a2b3c4d5e6f7890",
  amount: 0.01,
  payer: "123456",
  currency: "BTC",
  custom_data: { "order_id": "123" }
};
const appToken = "your_app_token";
const secretHash = crypto
  .createHmac('sha256', appToken)
  .update(JSON.stringify(webhookPayload))
  .digest('hex');

if (secretHash === webhookData.secret_hash) {
  console.log("Webhook signature verified");
} else {
  console.log("Invalid webhook signature");
}
```

<mark style="color:red;">**Важно**</mark><mark style="color:red;">:</mark>

* Всегда проверяйте secret\_hash, чтобы убедиться, что вебхук отправлен от нашего сервера.
* Храните токен API в безопасном месте и не передавайте его в запросах.


---

# 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://just-trade.gitbook.io/just-trade-docs/obshaya-informaciya/vebkhuki.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.
