# Payees

A **payee** is a registered counterparty under your seller account — a sub-merchant, marketplace seller, or any other recipient that is eligible to receive payouts and split shares. Every payout and split rule line targets a payee.

Payees are managed through the Payments REST API with a Bearer token. Every payee operation is scoped to the seller account behind your Bearer token: the `sellerAccountId` and `legalEntityId` are derived from the token and are **never** read from the request body, and a payee belonging to another seller returns `404` (so payee IDs cannot be probed across sellers).

---

## REST — Full CRUD

**Auth: Bearer token** (`Authorization: Bearer <token>`)

| Operation | Method & path |
|-----------|---------------|
| List payees | `GET /payments-api/v1/payees?limit={n}&offset={n}` |
| Get a payee | `GET /payments-api/v1/payees/{payee_id}` |
| Create a payee | `POST /payments-api/v1/payees` |
| Update a payee | `PATCH /payments-api/v1/payees/{payee_id}` |
| Delete a payee | `DELETE /payments-api/v1/payees/{payee_id}` |

Every operation is scoped to the seller account behind your Bearer token. `role` accepts the lowercase values `contractor` and `tax`.

> [!TIP]
> **Onboarding a payee just to pay it?** `POST /payments-api/v1/payees/setup` creates a payee **and** its first payout method in a single atomic call, so you can pay a brand-new payee in two requests total. See the [2-call quick path](https://docs.fynex.ai/payments-api/v2/docs#tag/payouts) in the Payouts guide.

### Payee response shape

All single-payee responses (`GET` / `POST` / `PATCH`) return the same object; the list endpoint wraps an array of these under `payees`:

```json
{
  "id": 101,
  "legalEntityId": 77,
  "merchantId": "16ddc5f1-39ca-4b7c-9bfa-bf5779b8c117",
  "displayName": "Acme Supplies Ltd",
  "role": "Contractor",
  "status": "Active",
  "isActive": true,
  "payeeContractId": "pc_001",
  "email": "finance@acme.example.com",
  "phone": "+447700900123",
  "businessName": "Acme Supplies Limited",
  "businessType": "limited_company",
  "businessAddress": "1 Example Street, London, GB",
  "taxId": "GB123456789",
  "createdAt": "2026-06-05T10:00:00Z",
  "updatedAt": "2026-06-05T10:00:00Z"
}
```

### List payees

```
GET /payments-api/v1/payees?limit={n}&offset={n}
```

Returns a paginated list of payees belonging to your seller account. `limit` (1–100, default 20) and `offset` (≥0) are tolerant — out-of-range or non-numeric values silently fall back to the defaults.

```bash
curl -sS "https://api.fynex.ai/payments-api/v1/payees?limit=20&offset=0" \
  -H "Authorization: Bearer $FYNEX_TOKEN"
```

```json
{ "payees": [ { "id": 101, "displayName": "Acme Supplies Ltd", "role": "Contractor", "status": "Active" } ], "total": 1, "limit": 20, "offset": 0 }
```

### Get a payee

```bash
curl -sS "https://api.fynex.ai/payments-api/v1/payees/101" \
  -H "Authorization: Bearer $FYNEX_TOKEN"
```

A payee that does not exist, or belongs to another seller, returns `404`.

### Create a payee

`sellerAccountId` and `legalEntityId` are **not** accepted in the body — they are derived from your token. A wallet in your seller account's currency is provisioned for the payee automatically.

```bash
curl -sS -X POST "https://api.fynex.ai/payments-api/v1/payees" \
  -H "Authorization: Bearer $FYNEX_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "displayName": "Acme Supplies Ltd",
    "role": "contractor",
    "payeeContractId": "pc_001",
    "email": "finance@acme.example.com",
    "businessName": "Acme Supplies Limited",
    "taxId": "GB123456789"
  }'
```

Returns `201 Created` with the payee object. A `payeeContractId` already in use within your seller account returns `409 Conflict`.

### Update a payee

`PATCH` is a partial update — send only the fields you want to change; omitted fields are left untouched.

```bash
curl -sS -X PATCH "https://api.fynex.ai/payments-api/v1/payees/101" \
  -H "Authorization: Bearer $FYNEX_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{ "displayName": "Acme Supplies (EU) Ltd", "email": "eu-finance@acme.example.com" }'
```

Returns `200 OK` with the updated payee object. A foreign/unknown `payee_id` returns `404`.

> [!NOTE]
> `role` is immutable after creation. Supplying a `role` that differs from the payee's current role returns `400` (`role cannot be changed after creation`) — the payee's wallet is provisioned by role at creation time and is not re-provisioned on update. Sending the same `role`, or omitting it, is fine.

#### Archive / restore via `status`

`status` accepts the lowercase values `active` and `disabled`. Setting it archives or restores the payee; `isActive` is kept in sync automatically (you do not send it):

```bash
# Archive (equivalent to DELETE, see below)
curl -sS -X PATCH "https://api.fynex.ai/payments-api/v1/payees/101" \
  -H "Authorization: Bearer $FYNEX_TOKEN" -H "Content-Type: application/json" \
  -d '{ "status": "disabled" }'

# Restore a previously archived payee
curl -sS -X PATCH "https://api.fynex.ai/payments-api/v1/payees/101" \
  -H "Authorization: Bearer $FYNEX_TOKEN" -H "Content-Type: application/json" \
  -d '{ "status": "active" }'
```

Restoring is refused with `409 Conflict` while the payee may not be paid:

- your seller account cannot currently receive payouts, or
- the payee is a [vendor's](/payments-api/v2/docs/vendors.md) payee and the vendor cannot currently receive payouts, is `blocked`, or is still being screened (`verification.status` `pending_fynex`, `reason: screening`).

```json
{ "error": "payee cannot be enabled while its seller or vendor cannot receive payouts, or while its vendor is declined or not yet screened", "code": "conflict" }
```

These are the same conditions under which a payout would be refused, so a restored payee is one that can actually be paid. The payee stays archived and nothing else changes; retrying does not help until the restriction is lifted. Sending `"status": "active"` for a payee that is already active is not a restore and is never refused. A vendor's payee needs no restore at all: it is enabled automatically the moment the vendor's screening passes. If your own seller account cannot receive payouts, contact Fynex support. Archiving (`"status": "disabled"`) is never refused.

### Delete (archive) a payee

`DELETE` is **non-destructive and reversible**: it *archives* the payee by setting its status to `Disabled` (and `isActive` to `false`). The payee is **not** removed — a subsequent `GET /payees/{payee_id}` still returns it (now `Disabled`), and you can restore it with `PATCH {"status":"active"}` unless a restriction above refuses it (`409`).

```bash
curl -sS -X DELETE "https://api.fynex.ai/payments-api/v1/payees/101" \
  -H "Authorization: Bearer $FYNEX_TOKEN"
```

```json
{ "archived": true }
```

> [!WARNING]
> **Archiving a payee that is still referenced by an active split rule will cause its payouts to fail — by design.** The split/payout engine is fail-closed: it never routes funds to a `Disabled` payee. If an archived payee is still a target of an active split rule, the affected split executions and payouts **fail with an explanatory error** (funds are never partially routed or silently dropped) until you either restore the payee (`PATCH {"status":"active"}`) or remove it from the split rule. The split-rule lines themselves are left untouched by archiving, so restoring the payee cleanly resumes payouts.

Returns `200 OK`. Archiving an already-archived payee is a no-op that still returns `200`. A foreign/unknown `payee_id` returns `404`. `DELETE` is exactly equivalent to `PATCH {"status":"disabled"}` — use whichever fits your client.

---

## Hosted payee onboarding contract (ONBOARD-01)

This is the contract for the planned hosted onboarding session. **It is not a
registered public route yet.** Until the runtime session store, redirect
handler, and webhook consumer implement these guarantees, integrations must
use the existing payee verification routes (`POST /payees/{payee_id}/verification`)
or vendor verification link route. No identity or money-moving endpoint is
advertised by this contract-only slice.

### Proposed operation

```http
POST /payments-api/v1/payees/{payee_id}/onboarding-sessions
Authorization: Bearer <seller_sk_key>
Idempotency-Key: <stable-client-key>
Content-Type: application/json

{ "returnUrl": "https://merchant.example/payees/onboarding/complete" }
```

The authenticated seller owns the payee: a payee belonging to another seller
is indistinguishable from an unknown payee and returns `404`. The operation
must not accept `sellerAccountId`, `legalEntityId`, or an identity-provider
applicant id from the caller. It creates no payout method and moves no money.

The successful response is:

```json
{
  "sessionId": "pos_01J...",
  "payeeId": 101,
  "onboardingUrl": "https://onboarding.fynex.ai/payee/pos_01J...",
  "expiresAt": "2026-09-15T12:00:00Z",
  "status": "pending"
}
```

`returnUrl` is optional only when the seller has a configured default. When
provided it must be HTTPS, have no userinfo, resolve to a public address, and
match the seller's allowed-return-hosts configuration. The service validates
it before creating a session; it never reflects an unvalidated URL into a
redirect.

### Session, replay, and completion semantics

- A session is owned by exactly one seller and payee, expires at `expiresAt`,
  and is unusable after expiry (`410 onboardingSessionExpired`). Expiry is
  server-enforced, not merely a UI timer.
- `Idempotency-Key` is required and scoped to the seller and payee. The same
  key with an equivalent body returns the original session (`200`); reusing it
  with a different `returnUrl` returns `409 idempotencyConflict`. A retried
  request never creates a second provider applicant or session.
- Opening the URL is safe to repeat. The provider's hosted result is accepted
  only after a verified provider webhook updates the payee's verification
  state. A browser redirect is advisory and cannot enable payouts by itself.
- On completion, the browser is redirected to the validated `returnUrl` with
  only opaque `sessionId` and `status` parameters. No identity document,
  provider token, or secret is placed in the URL. If no return URL is usable,
  the session ends on a Fynex-hosted status page.
- The seller receives the existing payee verification webhook/event state
  transition. Webhook delivery is signed, retried until a `2xx`, and must be
  consumed idempotently; duplicate events do not create a second transition.

The route remains intentionally absent from OpenAPI until these runtime
properties have a durable implementation and authenticated integration tests.

## Common pitfalls

| Pitfall | Resolution |
|---------|------------|
| Sending `sellerAccountId` / `legalEntityId` in a REST body | They are ignored — REST payees are always pinned to the seller account behind your Bearer token. |
| Using an uppercase `role` on REST | REST accepts the lowercase values `contractor` and `tax`; anything else returns `400`. |
| Expecting REST `DELETE` to remove the payee | REST `DELETE` *archives* (status `Disabled`); the payee stays queryable and is restorable via `PATCH {"status":"active"}`, except while the seller or the vendor it pays is restricted (`409`). |

## See also

- **[Payout Methods](https://docs.fynex.ai/payments-api/v2/docs#tag/payout-methods)** — Register bank accounts as payout destinations for a payee.
- **[Payouts](https://docs.fynex.ai/payments-api/v2/docs#tag/payouts)** — Send money from a seller wallet to a payee
