# Ключ идемпотентности

Ключ идемпотентности — это уникальное значение, которое создаётся на стороне клиента и отправляется на сервер вместе с запросом.\
\
Ключ идемпотентности (Idempotency-Key) направляется в header с типом данных UUID в методе api/Document/Create\
Используется для недопущения дублирования  документов в системе Алмаз. \
При отправке Idempotency-Key проверяется уникальность. Если Idempotency-Key не уникальный документ не создается.\
&#x20;Пример:<br>

```postman_json
--header 'Idempotency-Key: db6de35f-b0d6-4d68-a994-d8222f17dea7'
--header 'Content-Type: application/json'
--header 'Authorization: Bearer ....'
--data '{ 
  "Person": {
    "LastName": "string",
    "FirstName": "string",
    "MiddleName": "string",
    "IsResident": "string",
    "Phone": "string",
    "Passport": {
      "Serial": "string",
      "Number": "string",
      "DateIssue": "2019-08-24",
      "RegName": "string",
      "RegCode": "string",
      "Birthday": "2019-08-24",
      "BirthPlace": "2019-08-24",
      "BirthCountry": "string",
      "RegAddress": "string",
      "PostalAddress": "string"
    }
  },
  "Document": {
    "Number": "string",
    "Date": "2019-08-24",
    "Sum": "string"
  }
}
```

Если Idempotency-Key при валидации уникальный то документ будет создан.\
Если Idempotency-Key при валидации не уникальный  ответ от сервера будет:<br>

```json
{
    "documentId": "dd85219b-3542-407f-a965-774179766453",
    "code": 2,
    "codeTitle": "ServerError",
    "description": "Документ уже создан",
    "requestId": "0HN54K7OE2535:00000001"
}
```

Проверка статуса платежа по idempotency-Key

Для проверки статуса платежа необходимо использовать метод api/Payments/GetStatusByIK

Body:

```json
{
  "IdempotencyKey": "uuid"
}
```

Если документ с таким idempotency-Key был найдет то в ответе будет следующее:<br>

```json
{
    "gatewayId": "uuid",
    "sum": int,
    "state": int,
    "documentId": "string",
    "status": "string",
    "code": 0,
    "codeTitle": "Ok",
    "requestId": "0HN67BRHAPBP6:00000001"
}
```

Если такой документ не найдет то в ответе будет следующее:<br>

```json
{
    "sum": 0,
    "state": 0,
    "code": 4,
    "codeTitle": "NotFound",
    "description": "Платеж не найден",
    "requestId": "0HN67BRHAPBP8:00000001"
}
```


---

# Agent Instructions: 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:

```
GET https://almaz-online.gitbook.io/rukovodstvo-polzovatelya-po-rabote-v-sisteme/9.-razdel-menyu-platezhnye-dokumenty/klyuch-idempotentnosti.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
