createCheckout
Creates an order and returns its hosted checkout URL. Call it from your backend.
function createCheckout(
params: CreateOrderRequest,
opts: CheckoutClientOptions
): Promise<CreateCheckoutResult>
opts needs apiBaseUrl, apiKey and checkoutBaseUrl; see Configuration.
params is also the request body of POST /api/v1/orders.
Parameters
Pass exactly one amount mode. Every other field is optional.
| Property | Type | Description |
|---|---|---|
requestedUsdcAmount | string | USDC mode: the order amount in USDC. |
requestedFiatAmount | string | Fiat mode, with requestedFiatCurrency. Converted to USDC at the current rate and rounded to 2 decimals; the order's USDC fields carry the result. |
requestedFiatCurrency | string | Fiat mode: ISO currency code, for example EUR. |
openAmount | OpenAmountInput | Open-amount mode: { currency, minAmount?, maxAmount?, presets? }. The customer types the amount in checkout. See Open-Amount Orders. |
idempotencyKey | string | Stable key per purchase: 8–128 letters, digits, _ or -. See idempotent order creation. |
destinationAddress | string | Payout wallet. Defaults to your payout wallet for the destination chain. |
destinationToken | string | Payout token alias or address. Defaults to your account setting. |
destinationChainId | number | Payout chain. Defaults to your account setting. |
feePayer | FeePayerType | MERCHANT, PAYEE or SPLIT. Defaults to your account setting. |
buyerFeeShareBps | number | Required with SPLIT: the customer's share of fees in basis points, 0–10000 in steps of 1000 (5000 = 50%). |
dynamicOrdersEnabled | boolean | false turns Dynamic Orders off for this order; omitted inherits your account setting. true fails with DYNAMIC_ORDERS_DISABLED when the account setting is off, and is not allowed with openAmount. |
enabledRails | string[] | Rail identifiers offered on this order, replacing your account's selection. Must not be empty. |
expiresInMinutes | number | Whole minutes the checkout stays open, from 30 to 10080 (7 days). Omitted, the order never expires. See checkout expiry. |
successUrl | string | null | Absolute http:// or https:// URL for the link shown after a successful payment. Any other scheme fails with 400. Surrounding whitespace is removed. See what successUrl and cancelUrl do. |
cancelUrl | string | null | Absolute http:// or https:// URL stored on the order and returned to you. Any other scheme fails with 400. Surrounding whitespace is removed. |
notes | Record<string, unknown> | null | Your own data, stored on the order and returned with it. |
The SDK throws before sending when the request has no amount mode or more than one; the API
answers the same request with 400. Leaving the amount out never creates an open-amount order.
Order amount limits
Every order must be at least the platform minimum, 1 USDC on the hosted API, and at most
10,000 USDC, the most the protocol settles in one request. Sandbox has the same limits. In fiat
mode the converted amount is checked: 9,500 EUR at 0.92 EUR per USD is 10,326.09 USDC and fails
with 400 AMOUNT_ABOVE_MAX. Exactly 10,000 USDC is allowed. For a larger purchase, create
several orders.
The 10,000 USDC limit also applies to each bank or app payment (Venmo, Cash App, Zelle and the other fiat methods), measured as the amount the payment settles on chain, fees included:
- With
feePayer: "MERCHANT"and a Base USDC payout, a payment normally settles at or slightly below the order amount, so a 10,000 USDC order fits. - When the customer pays the fees (
PAYEE, or their share underSPLIT), the fees are added on top. At 1.5% fees a 10,000 USDCPAYEEorder settles about 10,152 USDC, so the largestPAYEEorder these methods can take is about 9,850 USDC. - A payout outside Base USDC adds the bridge cost the same way, whoever pays the fees.
Over the limit, checkout lists those methods as unavailable for the amount, and starting a
payment on one fails with 400 INTENT_ABOVE_MAX:
This payment would be 10152.29 USDC with fees, above the 10000.00 USDC limit per payment.
Crypto payments are not affected. Apple Pay has its own, lower limit.
Dynamic Orders only suggest amounts within both limits, and an
open-amount range never goes above 10,000 USDC.
Checkout expiry
By default an order never expires: it stays open until it is paid or you cancel it. Pass
expiresInMinutes to close this checkout on your own schedule:
const { order, checkoutUrl } = await createCheckout(
{ requestedUsdcAmount: '25', expiresInMinutes: 120, idempotencyKey: 'order_12345' },
options,
);
// order.expiresAt: '2026-11-16T14:00:00.000Z'
The API sets expiresAt from its own clock and returns it on the order and in every order
webhook. After expiresAt:
- No payment started: the order becomes
CANCELLEDwithin about a minute andORDER_CANCELLEDfires. - A payment started in time: nothing is cancelled. That payment keeps its own
payment window and can still settle and fulfil the
order, however late. Only a new payment start is refused, with
410 ORDER_EXPIRED.
So expiresAt is the last moment a customer can start paying, not a deadline for the money to
arrive. Keep fulfilling on ORDER_FULFILLED.
The value must be a whole number from 30 to 10080; anything else, including a numeric string,
is a 400 validation failure. An idempotent retry returns the original order with its original
expiresAt, whatever expiresInMinutes the retry sends.
Payment reminders
Peer Pay does not message your customers. To remind a customer before the checkout closes, send the reminder yourself:
- On create, store
order.id,order.expiresAtand thecheckoutUrl. - Schedule a job for 30 minutes before
expiresAt. WithexpiresInMinutes: 120that is 90 minutes after you create the order. - When the job runs, skip it if you already received
ORDER_FULFILLEDorORDER_CANCELLEDfor the order. If you receivedPAYMENT_CREATEDand noPAYMENT_EXPIRED,PAYMENT_FAILEDorPAYMENT_CANCELLEDafter it, the customer is already paying; skip it too. - Otherwise send your own email or message with the
checkoutUrl.
Idempotent order creation
Pass a stable idempotencyKey per purchase and reuse it on every retry, including after a
timeout. A replay returns the original order with idempotentReplay: true, orderToken: null and
checkoutUrl: null. The token cannot be recovered, so save the first checkoutUrl on your
backend and check for null before redirecting. createCheckoutAndRedirect returns a replay
without navigating.
A replay with a different amount or amount mode fails with 409 IDEMPOTENCY_KEY_CONFLICT. Fiat
mode compares the fiat amount and currency, so a rate change between retries is not a conflict.
Other fields on a replay are ignored.
Returns
type CreateCheckoutResult = {
order: CheckoutOrder;
checkoutUrl: string | null;
} & (
| { orderToken: string; idempotentReplay?: never }
| { orderToken: null; idempotentReplay: true }
);
checkoutUrl includes the order token, and is null only on an idempotent replay.
To open checkout with a payment method already chosen, append &method=<value> to checkoutUrl:
a rail identifier such as venmo, or a Zelle bank (zelle-bofa,
zelle-capitalone, zelle-chase or zelle-citi) for a customer who picked their bank on your
site. The SDK adds it with preselectedMethod, which
also explains what checkout does when the order or the customer's device can't take the method.
Example
import { createCheckout } from '@zkp2p/pay-sdk';
const checkout = await createCheckout(
{
requestedFiatAmount: '75.00',
requestedFiatCurrency: 'EUR',
idempotencyKey: 'order_12345',
destinationChainId: 8453,
destinationToken: 'USDC',
destinationAddress: '0x742d35Cc6634C0532925a3b844Bc9e7595f8fE71',
successUrl: 'https://example.com/success',
notes: {
orderId: 'order_12345',
customerId: 'cust_67890',
},
},
{
apiBaseUrl: 'https://api.pay.peer.xyz',
checkoutBaseUrl: 'https://pay.peer.xyz',
apiKey: process.env.ZKPAY_API_KEY!,
}
);
console.log(checkout.order.id); // cmf5k2x9d0001abcd1234efgh
console.log(checkout.checkoutUrl); // null on a replay: use the URL you saved
What successUrl and cancelUrl do
Neither URL moves the customer on its own, and neither proves payment.
successUrl: after a successful payment, checkout shows a Return to link with your business name, which the customer has to click. Embedded checkout does not show it. The link addsorder_idandstatus=success, plus, when known,payment_id,intent_hashandtx_hashfor a bank or app payment, orrequest_idandtx_hashfor a crypto payment.cancelUrl: stored on the order and returned to you. Checkout never navigates to it.
Never fulfill an order on a redirect or a query parameter. Fulfill on the ORDER_FULFILLED
webhook.
Errors
A rejected request throws PayApiError. Branch on errorCode; the
message is for logs. Validation failures (400 with no errorCode, details on fieldErrors),
401, 403 IP_NOT_ALLOWED and 429 work as on every endpoint; see
common errors.
| Status | errorCode | Cause |
|---|---|---|
400 | AMOUNT_BELOW_MIN | Below the platform minimum. See order amount limits |
400 | AMOUNT_ABOVE_MAX | Above 10,000 USDC, after any fiat conversion |
400 | AMOUNT_NON_POSITIVE | The fiat amount converts to 0 USDC |
400 | AMOUNT_BELOW_MERCHANT_MIN, AMOUNT_ABOVE_MERCHANT_MAX | Outside the order-size range set for your account. Contact Peer support to change it. Not applied in sandbox |
400 | DESTINATION_INVALID | No payout address is set for the destination chain, or destinationAddress does not match that chain's address format |
400 | PAYOUT_CONFIG_INVALID | Unsupported destination chain or token, or a payout outside Base USDC on an account that has not turned on payouts to another chain or token |
400 | NO_ELIGIBLE_PAYMENT_RAILS | None of the order's rails can be offered: each is unavailable or excluded by your verification route |
400 | MERCHANT_CONFIG_MISSING | The account has no checkout settings yet. Finish onboarding in the dashboard |
400 | DYNAMIC_ORDERS_DISABLED | dynamicOrdersEnabled: true while the account setting is off |
400 | OPEN_AMOUNT_INVALID, OPEN_AMOUNT_DISABLED | See open-amount errors |
403 | MERCHANT_TIER_FORBIDDEN | A live key whose plan is not activated (planActivatedAt is null); a tier alone is not enough. Activate Pro under Settings, Billing. Sandbox keys never get this |
403 | MERCHANT_MONTHLY_ORDER_LIMIT_EXCEEDED, MERCHANT_MONTHLY_VOLUME_LIMIT_EXCEEDED | The plan's monthly cap is reached. An open-amount order is checked against the volume cap when the customer starts a payment, not at creation |
409 | IDEMPOTENCY_KEY_CONFLICT | The idempotencyKey was used with a different amount or amount mode |
409 | MERCHANT_OWNERSHIP_CHANGED | The account changed owners while the order was being created. Nothing was saved; retry |
502 | EXCHANGE_RATE_LOOKUP_FAILED | No exchange rate for a non-USD requestedFiatCurrency or openAmount.currency. In fiat mode an unsupported currency code also returns this. Retry with a valid code |
INTENT_ABOVE_MAX comes from starting a payment, never from createCheckout. See
order amount limits.