# Payments and allocations

Money received, and which invoices it paid.

## POST /v1/payments

**Post receipts in bulk**

Posts through the ledger's receipt function: Dr bank, Cr receivables control, one balanced journal. The receipt number is minted here. A receipt with nothing allocated to it is a legitimate state — push it when the money arrives and allocate when you know what it paid.

Parameters:

- `Idempotency-Key` (header, required): Required on this call. Retrying with the same key returns the original response instead of doing it twice. Reusing a key with a different body is a 422.

Body (a JSON array of these):

- `external_ref` string, required
- `customer_external_ref` string
- `account_code` string
- `doc_date` string (date), required
- `amount` number, required: Positive. A refund is a credit note plus a payment out, never a negative receipt.
- `bank_account_id` string (uuid): Omit and the entity's active bank account is used.
- `reference` string
- `source_system` string: Your system's name, the same on every call (for example shop). Identifies your references.

```json
[
  {
    "external_ref": "string",
    "doc_date": "2026-12-01",
    "amount": 100
  }
]
```

Answers:

- `201` Created
- `422` Rejected by the ledger

## POST /v1/allocations

**Allocate payments to invoices**

Line-granular settlement. One R20 000 receipt clearing four invoices is four allocations, and the statement shows all four under the receipt. Over-allocating is refused by the database, not by the caller's discipline.

Parameters:

- `Idempotency-Key` (header, required): Required on this call. Retrying with the same key returns the original response instead of doing it twice. Reusing a key with a different body is a 422.

Body (a JSON array of these):

- `payment_external_ref` string, required
- `invoice_external_ref` string, required
- `amount` number, required

```json
[
  {
    "payment_external_ref": "string",
    "invoice_external_ref": "string",
    "amount": 100
  }
]
```

Answers:

- `201` Allocated
- `422` Over-allocation or wrong direction

## GET /v1/customers/{externalRef}/credit

**Customer credit — what the app shows**

Credit the customer can spend on the next order, how much of it they asked to have refunded instead, and the documents behind the number so the app can say where each credit came from. Use it to apply a credit to the next order rather than refunding it.

Parameters:

- `externalRef` (path, required)
- `sourceSystem` (query): Your system's name, the same on every call (for example shop). Identifies your references.

Answers:

- `200` credit_available, marked_for_refund, spendable_on_next_order, documents
- `404` Unknown customer

## GET /v1/credits

**Unused customer credit**

Every credit still unused, for customers the caller knows. Scoped by the CUSTOMER's external reference, not the document's: a credit note a bookkeeper typed into the office for one of your customers is that customer's credit, and your app should show it alongside the ones you pushed. raised_via says which screen it came from (OFFICE, or your system, …).

A credit note that was applied to an invoice has done its job and does not appear.

Each row carries document_id and doc_no as well as external_ref, so an office-raised credit with no external_ref can still be addressed by the refund endpoints.

Per customer, use GET /v1/customers/{ref}/credit instead.

Parameters:

- `sourceSystem` (query): Your system's name, the same on every call (for example shop). Identifies your references.
- `refundOnly` (query): Only credits the customer has asked to have refunded.
- `knownOnly` (query): Default true: only customers that have an external reference in this source system. false returns every open credit, including customers you have never pushed.

Answers:

- `200` total_unused, total_refund_requested, and the credits with unused, refund_requested, refund_requested_at, refund_note and raised_via
