Skip to main content

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.

PropertyTypeDescription
requestedUsdcAmountstringUSDC mode: the order amount in USDC.
requestedFiatAmountstringFiat mode, with requestedFiatCurrency. Converted to USDC at the current rate and rounded to 2 decimals; the order's USDC fields carry the result.
requestedFiatCurrencystringFiat mode: ISO currency code, for example EUR.
openAmountOpenAmountInputOpen-amount mode: { currency, minAmount?, maxAmount?, presets? }. The customer types the amount in checkout. See Open-Amount Orders.
idempotencyKeystringStable key per purchase: 8–128 letters, digits, _ or -. See idempotent order creation.
destinationAddressstringPayout wallet. Defaults to your payout wallet for the destination chain.
destinationTokenstringPayout token alias or address. Defaults to your account setting.
destinationChainIdnumberPayout chain. Defaults to your account setting.
feePayerFeePayerTypeMERCHANT, PAYEE or SPLIT. Defaults to your account setting.
buyerFeeShareBpsnumberRequired with SPLIT: the customer's share of fees in basis points, 0–10000 in steps of 1000 (5000 = 50%).
dynamicOrdersEnabledbooleanfalse 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.
enabledRailsstring[]Rail identifiers offered on this order, replacing your account's selection. Must not be empty.
expiresInMinutesnumberWhole minutes the checkout stays open, from 30 to 10080 (7 days). Omitted, the order never expires. See checkout expiry.
successUrlstring | nullAbsolute 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.
cancelUrlstring | nullAbsolute http:// or https:// URL stored on the order and returned to you. Any other scheme fails with 400. Surrounding whitespace is removed.
notesRecord<string, unknown> | nullYour 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 under SPLIT), the fees are added on top. At 1.5% fees a 10,000 USDC PAYEE order settles about 10,152 USDC, so the largest PAYEE order 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 CANCELLED within about a minute and ORDER_CANCELLED fires.
  • 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:

  1. On create, store order.id, order.expiresAt and the checkoutUrl.
  2. Schedule a job for 30 minutes before expiresAt. With expiresInMinutes: 120 that is 90 minutes after you create the order.
  3. When the job runs, skip it if you already received ORDER_FULFILLED or ORDER_CANCELLED for the order. If you received PAYMENT_CREATED and no PAYMENT_EXPIRED, PAYMENT_FAILED or PAYMENT_CANCELLED after it, the customer is already paying; skip it too.
  4. 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 adds order_id and status=success, plus, when known, payment_id, intent_hash and tx_hash for a bank or app payment, or request_id and tx_hash for 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.

StatuserrorCodeCause
400AMOUNT_BELOW_MINBelow the platform minimum. See order amount limits
400AMOUNT_ABOVE_MAXAbove 10,000 USDC, after any fiat conversion
400AMOUNT_NON_POSITIVEThe fiat amount converts to 0 USDC
400AMOUNT_BELOW_MERCHANT_MIN, AMOUNT_ABOVE_MERCHANT_MAXOutside the order-size range set for your account. Contact Peer support to change it. Not applied in sandbox
400DESTINATION_INVALIDNo payout address is set for the destination chain, or destinationAddress does not match that chain's address format
400PAYOUT_CONFIG_INVALIDUnsupported destination chain or token, or a payout outside Base USDC on an account that has not turned on payouts to another chain or token
400NO_ELIGIBLE_PAYMENT_RAILSNone of the order's rails can be offered: each is unavailable or excluded by your verification route
400MERCHANT_CONFIG_MISSINGThe account has no checkout settings yet. Finish onboarding in the dashboard
400DYNAMIC_ORDERS_DISABLEDdynamicOrdersEnabled: true while the account setting is off
400OPEN_AMOUNT_INVALID, OPEN_AMOUNT_DISABLEDSee open-amount errors
403MERCHANT_TIER_FORBIDDENA 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
403MERCHANT_MONTHLY_ORDER_LIMIT_EXCEEDED, MERCHANT_MONTHLY_VOLUME_LIMIT_EXCEEDEDThe 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
409IDEMPOTENCY_KEY_CONFLICTThe idempotencyKey was used with a different amount or amount mode
409MERCHANT_OWNERSHIP_CHANGEDThe account changed owners while the order was being created. Nothing was saved; retry
502EXCHANGE_RATE_LOOKUP_FAILEDNo 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.