# Record a payment against an invoice

Operation ID: `payInvoice`

Group: Accounting › Invoices

[Open in the interactive reference](https://docs.api.lensing.ai/lensing/v1/endpoints/payInvoice)

`POST /accounting/invoices/{id}/pay`

Retry-safe: A write that accepts Idempotency-Key: repeating a request with the same key replays the stored answer instead of executing twice.

Records a payment against an invoice. The payment is created for the invoice's customer and legal entity, using the entity's default electronic payment account. The payment is applied to the invoice and creates a journal entry in the general ledger. The response contains the new payment's id.

You can pay part of the amount due. For installments, send one request for each payment.

Send an Idempotency-Key header. If you retry with the same key and body, you get the original response and no second payment is created. Without the header, retrying a request that succeeded creates a second payment.

To see the reduced totalAmountDue and the increased paymentsApplied, use GET accounting/invoices/:id. To read the payment, use GET accounting/payments/:id.

## Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `Api-Version` | header | string · v1 | yes | The API version this request targets, named by its public identifier. Required on every request; omitting it, or naming a version this company does not have, is answered with 400. This document describes version `v1`. |
| `Idempotency-Key` | header | string | no | An opaque caller-chosen string (1-255 characters) that makes this request safe to retry. Repeating the same key with an identical request body replays the original response instead of re-executing - but only once that original request succeeded; a failed attempt re-executes on retry. Repeating the key with a different body is answered with 422. A key still in flight is answered with 409 - as is a key whose original request was interrupted before it finished, for a few minutes afterwards, until that attempt is presumed dead. A completed response stays replayable for 24 hours. The key is scoped to the caller, not to the action: reusing it for a different action is answered with 409 or 422 rather than treated independently. On read actions this header is ignored. On write actions that cannot offer the guarantee it is answered with `400 IDEMPOTENCY_NOT_SUPPORTED` rather than silently ignored. |
| `id` | path | string | yes | The unique identifier of the invoice you want to settle. |

## Request body

Required, `application/json`: payInvoiceInput.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `amount` | decimal | yes | The amount paid, in the invoice's currency. Must be greater than zero and may not exceed the amount still due. Example: `"1210.00"`. |
| `paymentDate` | date | yes | The date the payment was received or settled. Format YYYY-MM-DD. It drives the ledger posting and the reporting period. Example: `"2026-09-15"`. |
| `paymentType` | any | yes | How the payment was tendered. One of: `"check"`, `"ach"`, `"wire"`, `"creditCard"`, `"directDebit"`, `"sepaCreditTransfer"`. Example: `"wire"`. |
| `paymentNote` | string | no | A free-text note recorded on the payment, for example a bank reference or check number. Example: `"Remittance ref 88213"`. |
| `bankFeeAmount` | decimal | no | The fee the bank or processor deducted, in the invoice's currency. Recorded on the payment rather than subtracted from it. Send the gross amount in amount. Example: `"12.50"`. |

```json
{
  "amount": "1210.00",
  "paymentDate": "2026-09-15",
  "paymentType": "wire",
  "paymentNote": "Remittance ref 88213",
  "bankFeeAmount": "12.50"
}
```

## Response

`200` Success

Under `data` (payInvoiceOutput):

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `paymentId` | string | yes | The unique identifier for the payment created. Read it back with GET accounting/payments/:id, or re-read the invoice for its updated balance. Example: `"7d41e9b2-58c6-4a03-9e17-2b8f0c5d6a39"`. |

```json
{
  "data": {
    "paymentId": "7d41e9b2-58c6-4a03-9e17-2b8f0c5d6a39"
  },
  "diagnostics": [
    {
      "code": "PAYMENT_RECORDED",
      "message": "<message>",
      "severity": "error",
      "path": [
        "<path>"
      ],
      "details": {
        "paymentId": "3fa85f64-5717-4562-b3fc-2c963f66afa6"
      }
    }
  ]
}
```

## Response headers

- `Idempotency-Replayed` — Present and `true` only when this response replays a previously stored one for the same Idempotency-Key, rather than reflecting a live execution. Absent on a live response - never sent as `false`.

## Errors

| Code | Status |
| --- | --- |
| `INVOICE_NOT_FOUND` | 400 |
| `INVALID_AMOUNT` | 400 |
| `AMOUNT_EXCEEDS_DUE` | 400 |
| `IDEMPOTENCY_KEY_CONFLICT` | 409 |
| `IDEMPOTENCY_PAYLOAD_MISMATCH` | 422 |

## Advisories

Warnings and information a successful response can carry under `diagnostics`:

- `PAYMENT_RECORDED`

## Statuses

- `400` — Invalid request or business failure. Codes: INVOICE_NOT_FOUND, INVALID_AMOUNT, AMOUNT_EXCEEDS_DUE
- `401` — The request carries no valid access token.
- `403` — Not authorized
- `404` — Not found
- `409` — The Idempotency-Key is still being processed by another request.
- `422` — The Idempotency-Key was already used with a different request payload.
- `429` — Too many requests from this client address. The response has no body and no `Retry-After` header.
- `500` — Internal server error
