Skip to main content

Payouts

A payout pays one of your customers. You fund it in crypto, and the customer withdraws it to Venmo, Cash App, PayPal, Wise, Zelle, Revolut, Chime or a crypto wallet from a checkout link. This page shows the SDK calls; the Payouts API explains the lifecycle, the money rules and funding.

The payout amount, fees and accounting are always in USDC. On PayPal and Revolut the customer can withdraw in any of the app's catalog currencies; the fiat fields are for display only.

Server-side only

Every call sends your merchant API key in the X-API-Key header. Call these functions from your backend, never from a browser. The customer only sees the checkoutUrl you hand them.

import type { PayoutClientOptions } from '@zkp2p/pay-sdk';

const options: PayoutClientOptions = {
apiBaseUrl: 'https://api.pay.peer.xyz',
apiKey: process.env.ZKPAY_API_KEY!,
// Optional: fetcher (a custom fetch) and signal (an AbortSignal).
};

Create a payout​

import { createPayout } from '@zkp2p/pay-sdk';

const payout = await createPayout(
{
customerEmail: withdrawal.customerEmail,
merchantReference: withdrawal.id,
payout: {
amount: '100',
chainId: 8453,
tokenAddress: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913', // USDC on Base
},
funding: {
chainId: 8453,
tokenAddress: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913',
refundAddress: process.env.BASE_REFUND_ADDRESS!, // Base wallet you control
},
returnUrl: 'https://casino.example.com/cashier',
// rails: ['venmo', 'relay_8453'], // optional: offer only these payout methods
},
{ idempotencyKey: `withdrawal-${withdrawal.id}` },
options,
);

// Send payout.funding.amount to payout.funding.depositAddress before
// payout.funding.quoteExpiresAt, then give the customer payout.checkoutUrl.
  • payout is always USDC on Base (chain 8453) and sets the amount. The amount must be a whole multiple of your payout step (100 USDC by default); there is no maximum. The customer picks the coin and network they receive.
  • funding is the chain and token you send. refundAddress is where Relay returns funding it can't convert. On EVM chains it is optional: leave it out to refund the sending wallet, and set it when you fund from an exchange withdrawal, because Relay does not refund exchange wallets automatically. To fund with BTC, use chain 8253038 and token bc1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqmql8k8; refundAddress is then required and must be a Bitcoin address you control. See create a payout for every field and funding chain.
  • idempotencyKey is required; the SDK never makes one up. Use one key per withdrawal, 8–128 letters, digits, _ or -, and reuse it on every retry. A retry with the same key and body returns the same payout with idempotentReplay: true and its current checkoutUrl, so a timeout never creates a second payout. The same key with a different body is refused with 409 IDEMPOTENCY_KEY_CONFLICT.
  • rails limits which payout methods this payout offers (see the rail values). It never adds a method you or Peer turned off: those are dropped, and if none remain the call fails with 422 PAYOUT_REQUESTED_RAILS_UNAVAILABLE. An empty list, a repeated rail or an unknown id is a 400. Rail order doesn't matter on a retry, but a different set of rails with the same key conflicts.

Get, list and cancel​

import { cancelPayout, getPayout, listPayouts } from '@zkp2p/pay-sdk';

const view = await getPayout(payoutId, options);

const page = await listPayouts(
{ merchantReference: withdrawal.id, status: 'FUNDED', page: 1, limit: 20 },
options,
);
// page.items (newest first), page.page, page.limit, page.total

const cancelled = await cancelPayout(payoutId, options);

listPayouts filters by customerEmail (any letter case), merchantReference (exact) and status. Filters you leave out are not sent. page defaults to 1, and limit defaults to 20 with a maximum of 100.

cancelPayout works only while the payout's status and fundingStatus are both AWAITING_FUNDING and Relay has no record of a transfer to the deposit address; see cancel a payout and the errors below.

All four functions return a PayoutView (inside items for a list); createPayout adds checkoutUrl and idempotentReplay. The SDK exports PayoutCurrency, PayoutCurrencyType and PayoutFiatValue for the fiat display fields; see payout currency types.

Errors​

An API refusal throws a PayApiError with the API's message, statusCode, errorCode and responseObject; see error handling. A 400 validation failure has no errorCode and carries fieldErrors and formErrors instead. An invalid idempotencyKey, an empty payoutId or a missing apiKey throws a TypeError or Error before any request is sent.

import { PayApiError, createPayout } from '@zkp2p/pay-sdk';

try {
await createPayout(params, { idempotencyKey }, options);
} catch (error) {
if (error instanceof PayApiError && error.errorCode === 'PAYOUT_NOT_STEP_MULTIPLE') {
// Round the payout to a multiple of your payout step and retry.
}
throw error;
}
errorCodeStatusWhat to do
PAYOUT_NOT_STEP_MULTIPLE400Make the payout at least one payout step and a whole multiple of it
PAYOUT_TOKEN_UNSUPPORTED400Set payout to USDC on Base
PAYOUT_FUNDING_TOKEN_UNSUPPORTED400Fund with a token Peer allows for your account
PAYOUT_SANDBOX_UNSUPPORTED403Use a live API key; sandbox merchants can't create payouts
PAYOUTS_DISABLED403Turn on at least one payout app under Settings → Payouts
MERCHANT_CONFIG_MISSING409Finish setting up your merchant account
IDEMPOTENCY_KEY_CONFLICT409The key already created a payout with a different body; use a new key for a new withdrawal
IDEMPOTENCY_REQUEST_IN_PROGRESS409Retry with the same key once the first request finishes
PAYOUT_NO_RAILS_AVAILABLE422Peer has switched off every payout app you turned on; turn on another or try later
PAYOUT_REQUESTED_RAILS_UNAVAILABLE422None of the requested rails is available; widen or drop rails
PAYOUT_FUNDING_AMOUNT_TOO_LOW422Create a larger payout or fund with another token
PAYOUT_PRIVY_WALLET_FAILED, PAYOUT_RELAY_QUOTE_FAILED502Retry with the same key
PAYOUT_NOT_CANCELLABLE409The payout is no longer awaiting funding; responseObject has its status and fundingStatus
PAYOUT_FUNDING_DETECTED409Relay has a record of a transfer to the deposit address, so the payout can't be cancelled; if no USDC arrives, it expires
PAYOUT_RELAY_STATUS_FAILED502Retry the cancel

The full list is on the API page.

Webhooks​

Verify the signature first, as shown in verification. Then parse the body and narrow it with isPayoutWebhook: payout events carry a PayoutView in data, not the order envelope.

import {
isPayoutWebhook,
type PayoutPartialFillView,
type PayoutPartialPayment,
type PayoutSettlementBreakdown,
type WebhookPayload,
} from '@zkp2p/pay-sdk';

const payload = JSON.parse(rawBody) as WebhookPayload; // after verifying the signature
if (isPayoutWebhook(payload)) {
// payload.version === 2; payload.data is a PayoutView
if (payload.type === 'PAYOUT_ORDER_PARTIALLY_PAID') {
const partial: PayoutPartialPayment = payload.partialPayment;
recordPartialPayment(payload.data.merchantReference, partial.fill, partial.remainingAmount);
}
if (payload.type === 'PAYOUT_ORDER_SETTLED') {
const settlement: PayoutSettlementBreakdown | null = payload.data.settlement; // set on every SETTLED payout
const fills: PayoutPartialFillView[] = payload.data.partialFills;
markPaid(payload.data.merchantReference, payload.data.paidAmount, settlement, fills);
}
} else {
// An order, payment or dispute event: branch on payload.type.
}
  • version is 2 (PAYOUT_WEBHOOK_VERSION is 2) and changes only with a breaking change to the payout payload.
  • A payout can be paid in several payments. PAYOUT_ORDER_PARTIALLY_PAID fires once for each buyer payment that leaves something unpaid. Next to data it carries partialPayment: expectedAmount, paidAmount (this payment included), remainingAmount and the fill.
  • PAYOUT_ORDER_SETTLED always carries data.settlement, which says where the USDC went: paid by buyers, sent to a crypto address, returned to the customer's Peer wallet, swept as dust, or kept by a bridge on refunds.
  • Deduplicate on payload.id, which is the same for every webhook endpoint.

See payout events for every event and payload field.