# Failure lab: what goes wrong, and how to recover

Trigger the errors integrations hit most - the tenancy boundary, duplicates, missing scopes, idempotency, limits, screening and a failed payout - and see how each one tells you what to do.


## 1. Call a customer with your platform credential

The most common platform bug: calling a customer's routes with the platform's
own credential. Payezy answers `not_found`, the same as for an organization you
have never heard of, so ids cannot be probed.


Calls: GET /v1/orgs/{orgId}/accounts

Use a customer key for customer routes, and your platform credential for
`/v1/platforms/...` routes.


## 2. Create the same customer twice

Imports get retried. Because Acme already has `external_ref: acme-001`, a second
create is refused and tells you the existing customer's id.


Calls: POST /v1/platforms/{orgId}/customers

`details.customer_id` is the customer you already have. Treat this as success
in an import and carry on with that id.


## 3. Use a key without the scope

Keys get only the scopes you grant, and they cannot change later. Mint a
read-only key (no scopes means the read-only set), then try to add a recipient
with it.


Calls: POST /v1/platforms/{orgId}/customers/{customerId}/api-keys, POST /v1/orgs/{orgId}/counterparties

`scope_not_held` names the missing scope. Mint a new key with it; do not widen
reporting keys.


## 4. Reuse an Idempotency-Key with a different payment

An Idempotency-Key belongs to one intended payment. The first call succeeds; the
second sends the same key with a different amount and is refused.


Calls: POST /v1/orgs/{orgId}/payments, POST /v1/orgs/{orgId}/payments

Generate one key per intended payment and store it with your own record. Retry
with the same key and identical body; a changed payment gets a new key.


## 5. Go over the single-transfer limit

Every organization has single-transfer and daily limits set by Payezy.
getPaymentLimits shows them; going over returns a specific code.


Calls: GET /v1/orgs/{orgId}/payment-limits, POST /v1/orgs/{orgId}/payments

Show the limit to the person before they submit. Only Payezy staff can change
limits.


## 6. Pay a blocked recipient

Recipients are screened. In the sandbox a name containing "Blocked" is blocked.
Adding it works; paying it does not.


Calls: POST /v1/orgs/{orgId}/counterparties, POST /v1/orgs/{orgId}/payments

Check `screening_status` when you add a recipient and keep blocked recipients
out of your pay flow.


## 7. Watch a payout fail

Some failures happen after the money leaves - the receiving bank says the
account is closed. In the sandbox an account number ending in 0002 fails.


Calls: POST /v1/orgs/{orgId}/counterparties, POST /v1/orgs/{orgId}/payments, POST /v1/sandbox/orgs/{orgId}/payments/{paymentId}/advance

`payment.updated` arrived with `status: failed`; the reserved 40.40 USD went
back to the available balance. getPayment shows `failure` with the reason to
show your customer.

