# Remittances

One customer payment for several invoices, under one number.

## POST /v1/remittances

**Record remittances: one payment for several invoices**

Records a payment the customer is about to make for several invoices under one remittance number of yours. That number is what the payer uses as the card payment's merchant reference or the EFT reference, so when the bank line or the gateway confirmation arrives it finds the remittance waiting and settles every invoice in it. An EFT needs no further call. The lines must add up to the total; with on_account the lines may add up to less (or be none), and the rest settles the customer's open invoices oldest due first. Recording a remittance number that already exists returns it with created false.

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):

- `remittance_no` string, required
- `total` number, required: What the payer was asked to pay. Positive.
- `lines` array of object, required
- `lines[].invoice_external_ref` string, required
- `lines[].amount` number, required: Positive.
- `customer_external_ref` string
- `account_code` string: Our account code, when customer_external_ref is not sent.
- `method` string: EFT, CARD, OZOW, GOOGLE_PAY, APPLE_PAY, OTHER: How the payer said they would pay. Either route still settles it. Default "EFT".
- `on_account` boolean: What the lines do not take is a payment on account. Default false.
- `source_system` string: Your system's name, the same on every call (for example shop). Identifies your references.

```json
[
  {
    "remittance_no": "string",
    "total": 100,
    "lines": [
      {
        "invoice_external_ref": "string",
        "amount": 100
      }
    ]
  }
]
```

Answers:

- `201` count, and remittances with remittance_id, remittance_no and created
- `400` Idempotency-Key header missing, or an empty list
- `409` A request with this Idempotency-Key is already in flight
- `413` More than 1000 remittances in one request
- `422` Incomplete remittance, lines that do not add up to the total, an unknown customer or account, or Idempotency-Key reused with a different body

## GET /v1/remittances/{remittanceNo}

**Where a remittance stands**

The remittance's status (OPEN, PAID or CANCELLED), method, total, when it was paid, and how many of its invoices are settled and how many are still waiting.

Parameters:

- `remittanceNo` (path, required): Your remittance number, as sent when it was recorded.
- `sourceSystem` (query): Your system's name, the same on every call (for example shop). Identifies your references.

Answers:

- `200` remittance_no, status, method, total, paid_at, invoices_settled, invoices_waiting
- `404` Unknown remittance

## POST /v1/remittances/{remittanceNo}/cancel

**Cancel an open remittance**

The payer gave up. Marks an OPEN remittance CANCELLED with the reason, so a payment that later arrives under its number is not matched to it. A remittance already paid or cancelled cannot be cancelled.

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.
- `remittanceNo` (path, required): Your remittance number, as sent when it was recorded.
- `sourceSystem` (query): Your system's name, the same on every call (for example shop). Identifies your references.

Body:

- `reason` string, required

```json
{
  "reason": "string"
}
```

Answers:

- `201` remittance_no, status CANCELLED, reason
- `400` Idempotency-Key header missing
- `409` Unknown, already paid or already cancelled; or a request with this Idempotency-Key is already in flight
- `422` No reason given, or Idempotency-Key reused with a different body

## POST /v1/remittances/{remittanceNo}/payment-confirmation

**Gateway says the remittance is paid**

The gateway's word, not the bank's. Posts the receipt into that gateway's clearing account and spreads it across the remittance's invoices; the bank is untouched until the settlement arrives under the same reference. Idempotent on the gateway reference, so a retried webhook pays nothing twice. Needs a key with the money scope.

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.
- `remittanceNo` (path, required): Your remittance number, as sent when it was recorded.
- `sourceSystem` (query): Your system's name, the same on every call (for example shop). Identifies your references.

Body:

- `gateway_code` string, required: The payment gateway, as set up for the company.
- `amount` number, required: Gross, as the customer paid it. Fees are handled at settlement.
- `gateway_ref` string: The gateway's reference for the payment. Omit and the remittance number is used.
- `method` string: Default "CARD".
- `paid_with` string: The gateway's payment type, e.g. Visa, Mastercard, MasterPass, EFT_OZOW. Payments the gateway pays out one at a time wait for their own bank line.
- `confirmed_at` string (date-time): Omit for now.
- `merchant_reference` string: The gateway's merchant reference, kept on the payment for matching the settlement report.

```json
{
  "gateway_code": "string",
  "amount": 100
}
```

Answers:

- `201` remittance_no, gateway_payment_id, status, invoices_settled, invoices_waiting
- `400` Idempotency-Key header missing
- `403` The key may not move money
- `404` Unknown remittance
- `409` A request with this Idempotency-Key is already in flight
- `422` Not confirmed (e.g. unknown gateway, wrong amount, remittance cancelled), or Idempotency-Key reused with a different body
