# Payment lifecycle

Source: https://docs.formance.com/modules/payments/connectors/generic/payment-lifecycle

Stack: v3.2

How the transactions your service returns from `GET /transactions` become payments and adjustments in Formance. For the shape of those transactions, see the [wire contract](https://docs.formance.com/modules/payments/connectors/generic/wire-contract).

## What your service can send

`type` and `status` are closed enums. Your service can send only the values below. Formance has no mapping for anything else, and no way to extend it.

| Wire `type` | Formance payment type |
| ----------- | --------------------- |
| `PAYIN`     | `PAY-IN`              |
| `PAYOUT`    | `PAYOUT`              |
| `TRANSFER`  | `TRANSFER`            |
| `OTHER`     | `OTHER`               |

| Wire `status`      | Formance payment status |
| ------------------ | ----------------------- |
| `PENDING`          | `PENDING`               |
| `SUCCEEDED`        | `SUCCEEDED`             |
| `FAILED`           | `FAILED`                |
| `CANCELLED`        | `CANCELLED`             |
| `EXPIRED`          | `EXPIRED`               |
| `REFUNDED`         | `REFUNDED`              |
| `REFUNDED_FAILURE` | `REFUNDED_FAILURE`      |
| `REFUND_REVERSED`  | `REFUND_REVERSED`       |
| `DISPUTE`          | `DISPUTE`               |
| `DISPUTE_WON`      | `DISPUTE_WON`           |
| `DISPUTE_LOST`     | `DISPUTE_LOST`          |
| `AUTHORISATION`    | `AUTHORISATION`         |
| `CAPTURE`          | `CAPTURE`               |
| `CAPTURE_FAILED`   | `CAPTURE_FAILED`        |
| `OTHER`            | `OTHER`                 |

What happens with anything outside these lists:

- **An unknown value is rejected, not mapped to `OTHER`.** A `type` or `status` string outside the enum fails to decode, and it fails the **whole page** of transactions, not just that row. The poll errors and retries, and its watermark does not advance until your service stops returning the value.
- **A missing or empty `type` or `status` becomes `OTHER`.** This produces no error.
- A `scheme` on the wire is ignored. Every Generic connector payment is recorded with scheme `OTHER`.

## Which statuses change the amount

Only three statuses change a payment's amount. Each one applies the transaction's own `amount` as a delta:

| Status             | Effect on the payment's amount                                                                                                                                  |
| ------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `CAPTURE`          | Adds the transaction's amount                                                                                                                                   |
| `REFUND_REVERSED`  | Adds the transaction's amount                                                                                                                                   |
| `REFUNDED`         | Subtracts the transaction's amount                                                                                                                              |
| `AUTHORISATION`    | No delta. When it is the **first** transaction recorded for the payment, the payment is created with amount `0` and the authorized figure as its initial amount |
| Every other status | No effect. The status is recorded in the payment's history and does not change the amount                                                                       |

## Statuses have no state machine

Formance does not check status transitions. Any status can follow any other, including moving backwards (for example `SUCCEEDED` then `PENDING`). Your service decides the sequence, and Formance records what it receives:

- Each distinct `(id, createdAt, status)` becomes one adjustment in the payment's history.
- The payment's current status is the adjustment with the latest `createdAt`, not the most recently received. A follow-up whose `createdAt` is earlier than an existing adjustment is recorded, but does not become the current status.
- A transaction that repeats an `(id, createdAt, status)` that is already recorded is dropped as a duplicate, even when its `amount` or `metadata` has changed.
- A transaction is only read again if its `updatedAt` is strictly later than the connector's watermark. See [incremental sync](https://docs.formance.com/modules/payments/connectors/generic/wire-contract#pagination-and-incremental-sync).

## How follow-up transactions attach

A payment is identified by `(reference, type, connector)`:

- A transaction **without** `relatedTransactionID` uses its own `id` as the reference.
- A transaction **with** `relatedTransactionID` uses that value as the reference. It becomes an adjustment on that payment, keeping its own `id`, status, amount, and metadata.

Because `type` is part of the key, **every related transaction must repeat its parent's `type`**. If it doesn't, nothing errors. You get a second payment under the same reference with a different type, and the parent's amount stays where it was.

The first transaction recorded for a payment fixes the payment itself: its initial amount, starting amount, creation time, asset, source and destination accounts, and metadata. Later transactions never update those fields. Only `CAPTURE`, `REFUND_REVERSED`, and `REFUNDED` deltas change the amount afterwards. No check confirms that the parent exists. If a related transaction arrives before its parent, the related transaction creates the payment.

## Patterns that record a wrong amount without an error

- **`CAPTURE`, `REFUND_REVERSED`, or `REFUNDED` as the first transaction for a payment.** The payment is created with the transaction's amount, and then the delta is applied on top. That doubles the amount for `CAPTURE` and `REFUND_REVERSED`, and zeroes it for `REFUNDED`. Always send the original transaction before its follow-ups.
- **Refunding by changing the original's status.** Re-sending the original `id` with `status: REFUNDED` records a new adjustment and subtracts the original's full `amount`. For a partial refund, send a separate transaction with its own `id`, `relatedTransactionID` set to the original, and the refunded amount.
- **`AUTHORISATION` followed by `SUCCEEDED`.** The amount stays at `0`, because only `CAPTURE` adds to it.

## Common lifecycles

In each lifecycle below, every follow-up transaction has its own `id`, repeats the original's `type`, and sets `relatedTransactionID` to the original's `id`.

- **Authorize and capture.** Send `AUTHORISATION` first. Then send one or more `CAPTURE` transactions, each with the captured amount. Each one adds to the payment's amount, so partial captures accumulate. `CAPTURE_FAILED` is recorded and changes nothing.
- **Refund.** Send `REFUNDED` with the refunded amount. The payment's amount is decremented by that amount. `REFUND_REVERSED` adds it back, and `REFUNDED_FAILURE` changes nothing.
- **Dispute.** `DISPUTE`, followed by `DISPUTE_WON` or `DISPUTE_LOST`, is recorded, and none of the three changes the amount. If a lost dispute moves funds, send the movement separately as `REFUNDED`.

## Payouts and transfers initiated through Formance

For a payout or transfer created through Formance (`POST /payouts` or `POST /transfers`), the status of the matching payment sets the status of the initiation:

| Payment status                                     | Initiation status |
| -------------------------------------------------- | ----------------- |
| `SUCCEEDED`, `CAPTURE`, `REFUND_REVERSED`          | `PROCESSED`       |
| `FAILED`, `CANCELLED`, `EXPIRED`, `CAPTURE_FAILED` | `FAILED`          |
| `PENDING`, `AUTHORISATION`                         | `PROCESSING`      |
| `REFUNDED`                                         | `REVERSED`        |
| `REFUNDED_FAILURE`                                 | `REVERSE_FAILED`  |
| `DISPUTE`, `DISPUTE_WON`, `DISPUTE_LOST`, `OTHER`  | `UNKNOWN`         |

The Generic Connector does not write ledger postings. It records payments and their adjustments in Payments and publishes events. Turning those into ledger entries is a separate step in your integration.

## See also

- [Wire contract](https://docs.formance.com/modules/payments/connectors/generic/wire-contract): the `TransactionType` and `TransactionStatus` enums in full.
- [How it Works](https://docs.formance.com/modules/payments/connectors/generic/how-it-works): the polling model and the endpoints your service exposes.
