> For the complete documentation index, see [llms.txt](https://developers.coincircuit.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developers.coincircuit.io/webhooks/readme/invoices.md).

# Invoices

Invoice webhook events and example payloads.

Invoice webhooks track invoice creation, updates, payment, and expiry.

Use these events to keep invoice state in sync with your system.

### Field descriptions

Invoice webhook events use `data.invoice`.

Some invoice events also include `data.payments`.

| Field                              | Type                 | Description                             |
| ---------------------------------- | -------------------- | --------------------------------------- |
| `data.invoice.id`                  | `string`             | Unique invoice identifier.              |
| `data.invoice.reference`           | `string`             | Your invoice reference.                 |
| `data.invoice.amount`              | `string`             | Invoice amount as a decimal string.     |
| `data.invoice.amountPaid`          | `string`             | Amount paid so far.                     |
| `data.invoice.currency`            | `string`             | Invoice currency.                       |
| `data.invoice.status`              | `string`             | Invoice payment status.                 |
| `data.invoice.isRefunded`          | `boolean`            | Whether the invoice has been refunded.  |
| `data.invoice.state`               | `'open' \| 'closed'` | Invoice state.                          |
| `data.invoice.description`         | `string \| null`     | Optional invoice description.           |
| `data.invoice.expiresAt`           | `string \| null`     | Expiry timestamp.                       |
| `data.invoice.paidAt`              | `string \| null`     | Paid timestamp when available.          |
| `data.invoice.periodStart`         | `string \| null`     | Billing period start when applicable.   |
| `data.invoice.periodEnd`           | `string \| null`     | Billing period end when applicable.     |
| `data.invoice.nextPaymentDate`     | `string \| null`     | Next scheduled payment date.            |
| `data.invoice.metadata`            | `object \| null`     | Custom metadata.                        |
| `data.invoice.successUrl`          | `string`             | Redirect URL used after success.        |
| `data.invoice.cancelUrl`           | `string`             | Redirect URL used after cancellation.   |
| `data.invoice.customer`            | `object`             | Customer information.                   |
| `data.invoice.customer.telegramId` | `string \| null`     | Customer Telegram ID when available.    |
| `data.invoice.createdAt`           | `string`             | Creation timestamp.                     |
| `data.invoice.updatedAt`           | `string`             | Last update timestamp.                  |
| `data.payments`                    | `array \| null`      | Payment activity linked to the invoice. |

{% hint style="info" %}
Invoice payloads include `metadata`, `successUrl`, `cancelUrl`, and billing period fields even when the values are `null`.
{% endhint %}

### Events

* `invoice.created`
* `invoice.updated`
* `invoice.paid`
* `invoice.expired`

### `invoice.created`

Sent when an invoice is created.

Use this event to create an invoice record or start an expiry timer.

```json
{
  "event": "invoice.created",
  "data": {
    "invoice": {
      "id": "inv_123456789_abcdef",
      "reference": "INV-2024-001",
      "amount": "1000.00",
      "amountPaid": "0.00",
      "currency": "NGN",
      "status": "pending",
      "isRefunded": false,
      "state": "open",
      "description": "Invoice for services rendered",
      "expiresAt": "2024-02-15T10:30:00.000Z",
      "paidAt": null,
      "periodStart": null,
      "periodEnd": null,
      "nextPaymentDate": null,
      "metadata": {
        "orderId": "ORDER-2024-001"
      },
      "successUrl": "https://example.com/invoice/inv-2024-001",
      "cancelUrl": "https://example.com/invoice/inv-2024-001",
      "customer": {
        "id": "123e4567-e89b-12d3-a456-426614174000",
        "email": "customer@example.com",
        "phone": "+2348123456789",
        "firstName": "John",
        "lastName": "Doe",
        "telegramId": null
      },
      "createdAt": "2024-01-15T10:30:00.000Z",
      "updatedAt": "2024-01-15T10:30:00.000Z"
    },
    "payments": null
  }
}
```

### `invoice.updated`

Sent when an invoice receives a payment or changes state.

Use this event to refresh totals and partial payment state.

```json
{
  "event": "invoice.updated",
  "data": {
    "invoice": {
      "id": "inv_123456789_abcdef",
      "reference": "INV-2024-001",
      "amount": "1000.00",
      "amountPaid": "500.00",
      "currency": "NGN",
      "status": "partial",
      "isRefunded": false,
      "state": "open",
      "description": "Invoice for services rendered",
      "expiresAt": "2024-02-15T10:30:00.000Z",
      "paidAt": null,
      "periodStart": null,
      "periodEnd": null,
      "nextPaymentDate": null,
      "metadata": {
        "orderId": "ORDER-2024-001"
      },
      "successUrl": "https://example.com/invoice/inv-2024-001",
      "cancelUrl": "https://example.com/invoice/inv-2024-001",
      "customer": {
        "id": "123e4567-e89b-12d3-a456-426614174000",
        "email": "customer@example.com",
        "phone": "+2348123456789",
        "firstName": "John",
        "lastName": "Doe",
        "telegramId": null
      },
      "createdAt": "2024-01-15T10:30:00.000Z",
      "updatedAt": "2024-01-15T10:30:00.000Z"
    },
    "payments": [
      {
        "sessionId": "cs_123456789_abcdef",
        "sessionReference": "ORDER-2024-001",
        "status": "confirmed",
        "asset": "USDT",
        "chain": "ethereum",
        "amount": "100.55",
        "txHash": "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef",
        "createdAt": "2024-01-15T10:30:00.000Z",
        "confirmedAt": "2024-01-15T10:35:00.000Z"
      }
    ]
  }
}
```

### `invoice.paid`

Sent when an invoice is fully paid.

Use this event to fulfill the order.

```json
{
  "event": "invoice.paid",
  "data": {
    "invoice": {
      "id": "inv_123456789_abcdef",
      "reference": "INV-2024-001",
      "amount": "1000.00",
      "amountPaid": "1000.00",
      "currency": "NGN",
      "status": "paid",
      "isRefunded": false,
      "state": "open",
      "description": "Invoice for services rendered",
      "expiresAt": "2024-02-15T10:30:00.000Z",
      "paidAt": "2024-01-15T10:35:00.000Z",
      "periodStart": null,
      "periodEnd": null,
      "nextPaymentDate": null,
      "metadata": {
        "orderId": "ORDER-2024-001"
      },
      "successUrl": "https://example.com/invoice/inv-2024-001",
      "cancelUrl": "https://example.com/invoice/inv-2024-001",
      "customer": {
        "id": "123e4567-e89b-12d3-a456-426614174000",
        "email": "customer@example.com",
        "phone": "+2348123456789",
        "firstName": "John",
        "lastName": "Doe",
        "telegramId": null
      },
      "createdAt": "2024-01-15T10:30:00.000Z",
      "updatedAt": "2024-01-15T10:30:00.000Z"
    },
    "payments": [
      {
        "sessionId": "cs_123456789_abcdef",
        "sessionReference": "ORDER-2024-001",
        "status": "confirmed",
        "asset": "USDT",
        "chain": "ethereum",
        "amount": "100.55",
        "txHash": "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef",
        "createdAt": "2024-01-15T10:30:00.000Z",
        "confirmedAt": "2024-01-15T10:35:00.000Z"
      }
    ]
  }
}
```

### `invoice.expired`

Sent when an invoice expires.

Use this event to close unpaid invoices.

```json
{
  "event": "invoice.expired",
  "data": {
    "invoice": {
      "id": "inv_123456789_abcdef",
      "reference": "INV-2024-001",
      "amount": "1000.00",
      "amountPaid": "0.00",
      "currency": "NGN",
      "status": "pending",
      "isRefunded": false,
      "state": "closed",
      "description": "Invoice for services rendered",
      "expiresAt": "2024-01-15T10:30:00.000Z",
      "paidAt": null,
      "periodStart": null,
      "periodEnd": null,
      "nextPaymentDate": null,
      "metadata": {
        "orderId": "ORDER-2024-001"
      },
      "successUrl": "https://example.com/invoice/inv-2024-001",
      "cancelUrl": "https://example.com/invoice/inv-2024-001",
      "customer": {
        "id": "123e4567-e89b-12d3-a456-426614174000",
        "email": "customer@example.com",
        "phone": "+2348123456789",
        "firstName": "John",
        "lastName": "Doe",
        "telegramId": null
      },
      "createdAt": "2024-01-15T10:30:00.000Z",
      "updatedAt": "2024-01-15T10:30:00.000Z"
    },
    "payments": null
  }
}
```


---

# 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://developers.coincircuit.io/webhooks/readme/invoices.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.
