# Invoices

This section describes methods for creating invoices and obtaining information about invoices.

The functionality of the accounts allows you to accept payment in the specified equivalent, and the coin and network are chosen by the payer

For example, you can create an invoice for payment of 100 USD, the payer will be asked to select\
coin and network in which it will be more convenient for him to pay, for example, in USDT, TRX, BNB and others.\
The amount due will be recalculated automatically at the exchange rate.

When paying, you can also additionally indicate the percentage to be paid (field `insurancePercent`),\
in this case, the payer will be shown the amount to be paid as 100 USD, but the payment amount, for example, in USDT will be equal`<AMOUNT TO PAY> * <USDT/USD RATE> + <insurancePercent>`\
Example: you created an invoice for payment of 75 USD and specified `insurancePercent` equal to 5. When choosing a payment coin, for example, USDT (we will assume that the USDT/USD rate is 1=1), the payer will be asked to pay 78.75 USDT (5% of 75 = 3.75)

You can also specify that the payer pays the network commission by specifying the `includeFee: true` parameter.\
In this case, the commission chosen by the payer will be added to the final payment amount.

It is possible to specify the percentage of price slippage (field `slippagePercent`).\
If it is indicated, then if the payer, when paying, sends an amount more or less than the payment amount by the specified percentage, then the account will be considered closed.\
Example: the payer needs to pay 100 USDT, you specified a slippage percentage of 0.5%.\
In this case, if the payer sends the amount of 99.99 USDT (from 99.5 to 100.5), the invoice will be considered completed

## API Interaction Scheme

{% @mermaid/diagram content="sequenceDiagram
Client ->> Merchant: Payment request
Merchant ->> Onchainpay: Creating invoice
Onchainpay ->> Merchant: Invoice
Merchant ->> Client: Payment link

```
Note over Client: Choosing payment coin/network
Note over Client: Sending coins

Onchainpay -->> Merchant: Payment webhook" %}
```

## Possible statuses

| Status      | Description                                                                            |
| ----------- | -------------------------------------------------------------------------------------- |
| `INIT`      | The user proceeded to payment                                                          |
| `ERROR`     | Error during creation or processing                                                    |
| `PROCESSED` | Executed                                                                               |
| `PENDING`   | Waiting for the full amount or waiting for transaction confirmations in the blockchain |
| `EXPIRED`   | Invoice expired                                                                        |
| `PARTIAL`   | Partial payment                                                                        |
| `OVERPAID`  | The invoice was paid in excess of the stated amount                                    |
| `REJECTED`  | Invoice rejected, contact support for clarification                                    |

When the status changes or a new transaction arrives, you will be sent a webhook to the URL specified when creating the order.

More information about webhooks can be found in the **Webhooks** section

## Invoice lifetime

The specified lifespan of the account extends to the period from *creation of the account* to *selection by the payer of coins and network for payment*

After selecting a coin and network, the payer will create an order with the maximum lifetime available for the selected network.

More details can be found in the orders section.


---

# 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://docs.onchainpay.io/api-reference/07invoices.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.
