# Platform: from zero to your customer's first payment

Onboard a business customer under your platform, verify it, give your servers a key for it, fund its account and pay a vendor - every step a real API call.


## 1. Start a sandbox platform

Platforms are invite-only and reviewed by Payezy, which is slow for a first
look. A sandbox platform is already active, so you can try every platform call
right away. It expires after 7 days.


Calls: POST /v1/sandbox/platforms

Your platform organization {{platform_id}} exists and is active. Everything a
platform does is scoped to this id - its team, its keys, its webhooks and its
links to customers.


## 2. Find your platform

Every integration starts by asking who the credential is. getMe lists each
organization you belong to with your role and permissions; the platform's
`org_id` is the `{orgId}` in every platform call.


Calls: GET /v1/me, GET /v1/platforms/{orgId}

Your membership on the platform carries permissions like
`platform:customers_add` and `platform:customer_keys`. The profile holds what
customers see: legal name, support email, the customer types you offer and your
enrollment link.


## 3. Listen for customer changes

Verification takes minutes to days in production, so you learn about it from
webhooks, not polling. Register an endpoint on your platform for
`platform_customer.updated`; it fires when a customer is created, activated,
restricted or reinstated.


Calls: POST /v1/orgs/{orgId}/webhooks

Endpoint {{platform_webhook_id}} now receives `platform_customer.updated`. Every
delivery carries `Payezy-Signature: t=...,v1=...`, an HMAC-SHA256 of
`<t>.<raw body>` with your signing secret. Reject anything older than five
minutes.


## 4. Create the customer

You already hold Acme's details, so create the organization for them instead of
sending an invitation. The customer is a separate organization linked to your
platform; you never become one of its members. `external_ref` is your own id
for Acme - if this request is retried, Payezy refuses a duplicate.


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

Acme Robotics is organization {{customer_id}}, status `kyc_required`, with a
draft KYB application. The response lists `required_documents` - the files you
upload next. Acme's owner exists as a member already, so you can act for them,
but their email is verified only for sign-in, not KYC.


## 5. File Acme's KYB

Nothing reaches the banking partner until Payezy staff review the application,
and they need documents: a certificate of formation for the business, plus a
photo ID and a proof of address for its controller. Then you submit, attesting
that Acme accepted the account agreement.


Calls: GET /v1/platforms/{orgId}/customer-terms, POST /v1/platforms/{orgId}/customers/{customerId}/onboarding/documents, POST /v1/platforms/{orgId}/customers/{customerId}/onboarding/documents, POST /v1/platforms/{orgId}/customers/{customerId}/onboarding/documents, POST /v1/platforms/{orgId}/customers/{customerId}/onboarding/submit

The application is `pending_review` and Acme is `kyc_pending`. In production a
Payezy reviewer approves it, sends it back with a message, or rejects it. Then
the banking partner verifies it and may ask for more documents
(`documents_required`), which you send with submitPlatformCustomerOnboardingDocuments.


## 6. Get Acme approved

In the sandbox you decide the outcome instead of waiting for a reviewer. Choose
`approve` here; the failure lab tries `request_changes` and `reject`.


Calls: POST /v1/sandbox/orgs/{orgId}/verification

Acme is `active` and its USD account is open. Your platform endpoint received
`platform_customer.updated` with `status: active` - that is the signal to let
Acme start using money features in your product.


## 7. Give your servers a key for Acme

Your platform's own credential never acts inside a customer's organization; try
it and you get `not_found`. To call Acme's accounts, recipients and payments
from your servers, mint a customer key with only the scopes you need. Money
scopes are opt-in.


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

Key {{key_id}} acts only inside Acme's organization and only with those scopes.
Every call it makes is recorded as `source=platform_api` with your platform id,
on Acme's activity log and on yours. If you unlink Acme, Payezy revokes the keys
you minted.


## 8. Listen for Acme's payments

Events are delivered to endpoints registered on the organization they are
about. Payment and verification events belong to Acme, so register an endpoint
on Acme's organization, using Acme's key.


Calls: POST /v1/orgs/{orgId}/webhooks

You now hear about Acme's deposits and payments. Many platforms point every
customer's endpoint at one URL and route on the customer in the path, as here.


## 9. Find Acme's account and funding details

Approval opened a USD account with a named virtual account at the banking
partner. Its routing and account numbers are what Acme gives payers - or what
you show inside your product.


Calls: GET /v1/orgs/{orgId}/accounts, GET /v1/orgs/{orgId}/accounts/{accountId}/funding

Account {{account_id}} has a balance of 0. Money sent over ACH, wire or FedNow to
the virtual account credits it. Balances come from Payezy's double-entry ledger,
reconciled hourly against the partner.


## 10. Fund the account

In production a payer sends money to the virtual account and it settles in
hours to days depending on the rail. In the sandbox you simulate the deposit.


Calls: POST /v1/orgs/{orgId}/accounts/{accountId}/simulate-deposit, GET /v1/orgs/{orgId}/accounts

5,000.00 USD is available. Acme's endpoint received `payment.updated` with
`purpose: deposit` and `status: completed`.


## 11. Add a recipient

Acme pays its vendor Globex. A recipient holds one or more bank or wallet
accounts and is screened before money can go to it.


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

Globex is recipient {{counterparty_id}}; its bank account {{external_account_id}}
is the default. Screening came back `clear`. A name with "Blocked" or "Review"
in the sandbox shows the other outcomes.


## 12. Price the payment

Rails differ in fee and speed. Quote first and show Acme the options, or send
`policy: cheapest` or `fastest` and let Payezy pick.


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

The cheapest rail is `{{rail}}`. Each option shows the fee, Payezy's share and
the network's, and when the money arrives.


## 13. Send the payment

Creating a payment reserves the amount plus fee immediately. The
`Idempotency-Key` makes retries safe: send the same key again and you get the
same payment back instead of paying twice.


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

Payment {{payment_id}} is `processing`. Had Acme set an approval policy and the
amount crossed its threshold, it would be `pending_approval` until an approver
approved it.


## 14. Watch it settle

The banking partner reports progress asynchronously. In the sandbox you move the
payment forward yourself; in production you wait for `payment.updated`.


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

The payment is `completed`. The 250.25 USD hold became a posted debit. If the
receiving bank had returned it, a later `payment.updated` with `returned` would
credit the money back.


## 15. Reconcile from your side

Platforms watch their whole book of customers. The platform transactions list
shows every customer's payments without minting keys.


Calls: GET /v1/orgs/{orgId}/payments/{paymentId}, GET /v1/platforms/{orgId}/transactions

You see the deposit and the payment, each with Acme's name. Reconcile them
against the webhook events you stored, using `id` and `status`.

