# Beneficiaries and validations

> How zulu identifies a beneficiary, when it registers them, how it compares their name and which validations run before money moves.

[Production]

There is no endpoint to create beneficiaries: the first withdrawal to a person or company registers them, and the following ones validate them.

## Identification

A beneficiary is identified by their document type and number (`documentType` + `documentNumber`). It may be the balance holder itself (one of its accounts) or a third party.

| `entityType` | Document                               | Name                                                                     |
| ------------ | -------------------------------------- | ------------------------------------------------------------------------ |
| `person`     | `CC`, `CE`, `PPT` or passport          | `firstName` and `lastName` (required), `middleName` and `secondLastName` |
| `company`    | `NIT`, with or without its check digit | `companyName` (required)                                                 |

**GET** `/v1/document-types` — List document types · [Sandbox · coming soon] · [See the reference](https://developers.zulu.com.co/en/reference/list-document-types.md)

## Registration and verification

- **If the beneficiary does not exist**, they are registered with the data you send.
- **If they already exist**, they must be verified and the name you send must match the registered one.
- **If the account is not registered** for that beneficiary, it is registered.

### How the name is compared

The name matches when it shares at least one word with the registered one, regardless of accents, case or order: "LUIS GOMEZ", "Gómez Luis" and "luis a. gómez" all match "Luis Gómez". Documents are compared by their digits, so a NIT with or without its check digit is the same.

## Accounts

| Field           | What it is                                                                                                      |
| --------------- | --------------------------------------------------------------------------------------------------------------- |
| `bankCode`      | 4-digit ACH code ([catalog](https://developers.zulu.com.co/en/reference/list-banks.md)). Needed for online ACH. |
| `accountType`   | `ahorros` or `corriente`; `savings`/`saving` and `checking` are aliases.                                        |
| `accountNumber` | Account number; leading zeros count.                                                                            |

## Validations and their order

| Rule | Operations |
| --- | --- |
| Validation order: verified user (403) → origin entity (422) → verified beneficiary and name (422) → method → balance with the fee (422) → COP account (422) → bank and account type (422) → order and debit → dispatch. The first failure answers; nothing is recorded. | [`createTransfer`](https://developers.zulu.com.co/en/reference/create-transfer.md) |

| HTTP | error | cause | Description |
| --- | --- | --- | --- |
| 400 | `BadRequestApiError` | `error in struct validation` | One or more fields fail their validation. `values` carries one message per field, keyed by its JSON path, naming the Go validator that failed. |
| 403 | `ForbiddenApiError` | `the user is not verified` | The user behind the credentials is not verified. In the sandbox: the workspace "verified" setting. |
| 422 | `UnprocessableEntityApiError` | `the beneficiary with document "%s" is not verified` | The beneficiary registered with that document is not verified. Test data: document `1111111111`. |
| 422 | `UnprocessableEntityApiError` | `the name does not match the beneficiary registered with document "%s"` | The name sent shares no word with the registered beneficiary's (format, accents and order are tolerated). Test data: document `2222222222`, registered as "Ana Pérez". |
| 422 | `UnprocessableEntityApiError` | `bank with code "%s" is not supported` | The `bankCode` is not an available bank (see `GET /v1/banks`). Test data: `9999`. |
| 422 | `UnprocessableEntityApiError` | `account type "%s" is not supported` | Unsupported account type. Body validation stops it first (400), so in practice it does not appear. |

## Test the validations

| Field | Value | Effect | Operations |
| --- | --- | --- | --- |
| `destination.bankAccount.accountNumber` | `0000000001` | The withdrawal goes out by ACH (`IN_PROGRESS`), reaches `SENT` and ends `REJECTED`; the debit is reversed and a webhook is sent for each change. | [`createTransfer`](https://developers.zulu.com.co/en/reference/create-transfer.md), [`getTransaction`](https://developers.zulu.com.co/en/reference/get-transaction.md), [`advanceTransaction`](https://developers.zulu.com.co/en/reference/advance-transaction.md) |
| `destination.bankAccount.accountNumber` | `0000000002` | The ACH dispatch does not queue: the withdrawal continues as a manual payment and answers `{status: IN_PROGRESS, method: MANUAL}`. | [`createTransfer`](https://developers.zulu.com.co/en/reference/create-transfer.md) |
| `destination.breBKey.key` | `@failbreb` | The Bre-B transfer fails: the withdrawal is left for manual payment and answers `{status: CREATED, method: MANUAL}`, as in production. | [`createTransfer`](https://developers.zulu.com.co/en/reference/create-transfer.md) |
| `destination.documentNumber` | `1111111111` | The beneficiary is registered but not verified: 422 `the beneficiary with document "1111111111" is not verified`. | [`createTransfer`](https://developers.zulu.com.co/en/reference/create-transfer.md) |
| `destination.documentNumber` | `2222222222` | The beneficiary is already registered as "Ana Pérez". A name sharing a word (regardless of accents, case or order) passes; any other answers 422 `the name does not match the beneficiary registered with document "2222222222"`. | [`createTransfer`](https://developers.zulu.com.co/en/reference/create-transfer.md) |
| `destination.bankAccount.bankCode` | `9999` | The bank is not in the catalog: 422 `bank with code "9999" is not supported`. | [`createTransfer`](https://developers.zulu.com.co/en/reference/create-transfer.md) |

With document `1111111111` the beneficiary is not verified; with `2222222222` they are already registered as "Ana Pérez", so "Luis Gómez" answers `422` and "Ana María Pérez" passes.
