Skip to main content

Integration Options

Create the order on your backend, then send the customer to the returned checkoutUrl: redirect the page, open a new tab, or embed checkout in an iframe. You can also hand the whole integration to a coding agent.

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

const checkout = await createCheckout(
{
requestedUsdcAmount: '50.00',
destinationChainId: 8453,
destinationToken: 'USDC',
successUrl: 'https://yoursite.com/payment/success',
notes: { merchantOrderId: orderId },
},
{
apiBaseUrl: 'https://api.pay.peer.xyz',
checkoutBaseUrl: 'https://pay.peer.xyz',
apiKey: process.env.ZKPAY_API_KEY!,
},
);

await db.orders.update({
where: { id: orderId },
data: { checkoutOrderId: checkout.order.id },
});

return checkout.checkoutUrl;

With an idempotencyKey, save the first checkoutUrl: a replay returns null. See idempotent order creation.

Drive your order state from webhooks, especially PAYMENT_SETTLED, PAYMENT_FAILED, PAYMENT_EXPIRED and ORDER_FULFILLED, and fulfill only on ORDER_FULFILLED. Do not cancel an order just because PAYMENT_EXPIRED arrived. Write the handler against webhook verification, which checks the signature over the raw body in Node, Python and Go.

In the browser, send the customer to the URL your backend returned:

window.location.assign(checkoutUrl);

After paying, the customer sees a link back to your successUrl. Nothing redirects automatically; see what successUrl and cancelUrl do.

New Tab​

window.open(checkoutUrl, '_blank');

Use this to keep your page open.

URL helpers​

getCheckoutUrl and redirectToCheckout make no request and ignore apiKey, so leave it out of their options.

getCheckoutUrl​

function getCheckoutUrl(
orderId: string,
orderToken: string,
opts: CheckoutClientOptions
): string

Rebuilds a checkout URL from a stored order id and token. createCheckout already returns it as checkoutUrl.

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

const url = getCheckoutUrl(storedOrderId, storedOrderToken, {
apiBaseUrl: 'https://api.pay.peer.xyz',
checkoutBaseUrl: 'https://pay.peer.xyz',
});
// https://pay.peer.xyz/?order=cmf5k2x9d0001abcd1234efgh&token=...

redirectToCheckout​

function redirectToCheckout(
orderId: string,
orderToken: string,
opts: CheckoutClientOptions
): void

Navigates the current tab to checkout with window.location.assign, so it runs only in a browser.

createCheckoutAndRedirect​

function createCheckoutAndRedirect(
params: CreateOrderRequest,
opts: CheckoutClientOptions
): Promise<CreateCheckoutResult>

Creates an order and redirects in one call.

Puts your API key in the browser

createCheckoutAndRedirect redirects, so it runs only in a browser, and order creation needs your merchant API key. Create the order on your backend and send the customer the returned checkoutUrl instead.

Embedded Iframe​

Load checkout with ensureEmbedModeUrl from @zkp2p/pay-sdk/embedded and listen for its events. Embedded checkout shows no link back to your successUrl, so drive your page from the checkout.success event and your webhooks.

import { useEffect, useRef } from 'react';
import { EMBED_EVENT_CHANNEL, ensureEmbedModeUrl } from '@zkp2p/pay-sdk/embedded';

export function EmbeddedCheckout({ checkoutUrl }: { checkoutUrl: string }) {
const iframeRef = useRef<HTMLIFrameElement | null>(null);

useEffect(() => {
const onMessage = (event: MessageEvent) => {
if (event.source !== iframeRef.current?.contentWindow) return;
if (!event.data || event.data.channel !== EMBED_EVENT_CHANNEL) return;

if (event.data.type === 'checkout.success') {
// show your confirmation; fulfill on the ORDER_FULFILLED webhook
}
if (event.data.type === 'checkout.failed') {
// show a failure message
}
if (event.data.type === 'checkout.closed') {
// close the iframe; this is not a payment failure
}
};

window.addEventListener('message', onMessage);
return () => window.removeEventListener('message', onMessage);
}, []);

return (
<iframe
ref={iframeRef}
title="Embedded Checkout"
src={ensureEmbedModeUrl(checkoutUrl)}
sandbox="allow-scripts allow-forms allow-same-origin allow-popups allow-popups-to-escape-sandbox"
/>
);
}

Each message is { channel: "zkp2p_checkout_embed_v1", type, timestamp, payload }:

typeSent whenpayload
checkout.successThe payment completedorder_id, payment_id, intent_hash, tx_hash, request_id (crypto), status: "success"
checkout.failedThe payment failed, was cancelled or was refundedorder_id, payment_id, intent_hash, error, status: "failed"
checkout.closedThe customer dismissed checkout; see beloworder_id, reason

Fields that are not known yet can be missing. An embedded payout checkout posts payout events instead; see embedding the customer checkout. A checkout grant page posts grant.created and grant.funding on the same channel before either checkout starts.

Sandbox requirements​

The sandbox attribute is optional. If you set it, keep the flags shown above: checkout needs allow-scripts, allow-same-origin and allow-forms to run, and these two to open payment apps:

FlagWhy
allow-popupsEmbedded checkout opens payment apps in a new tab, because providers including Cash App and PayPal refuse to load in a frame. Without this flag the browser silently drops clicks such as Pay with … and Confirm my payment.
allow-popups-to-escape-sandboxKeeps the payment app's tab from inheriting your iframe's sandbox, which can break it.
Symptom of a missing flag

If customers report that Pay with … does nothing, check the sandbox attribute first. A blocked popup shows no error, and the order later expires unpaid.

Dismissing the iframe​

When no payment method can take the order, for example because none has liquidity for the amount, embedded checkout shows a Go Back button that emits checkout.closed:

{
"channel": "zkp2p_checkout_embed_v1",
"type": "checkout.closed",
"timestamp": 1725000000000,
"payload": {
"order_id": "...",
"reason": "no_payment_methods"
}
}

Close the iframe without your checkout.failed handling. The order is untouched and the same checkout URL can reopen it.

Not proof that nothing was charged

A partially paid order returns to method selection for its remaining balance, and can emit checkout.closed from there. Before telling a customer nothing was taken, read the order by order_id with the Orders API or check your webhooks.

Let a coding agent integrate​

Sign in with the Peer Pay CLI, configure your merchant, and hand the integration to the coding agent in your project:

peer-pay-cli login --profile live
peer-pay-cli setup
peer-pay-cli handoff --profile live --project .

The handoff names your CLI profile and contains no credentials. The agent follows the public runbook, printed by peer-pay-cli integration runbook --profile live: order creation, the redirect, a raw-body webhook handler, webhook registration in sandbox and live, sandbox verification and go-live. Two endpoints support that flow, and you can call them yourself:

EndpointKeyWhat it does
POST /api/v1/sandbox/test-orderSandboxCreates, pays and settles a sandbox order and sends a signed ORDER_FULFILLED to your sandbox webhook. No money moves. Optional: requestedUsdcAmount (default 1.00), rail (one of your enabled rails), or orderId to settle an open sandbox order your store created instead. Wallet crypto rails require a buyer-controlled refundTo on that chain, including when a crypto-only merchant omits rail; fiat rails need none. Missing or invalid addresses return 400 CRYPTO_REFUND_ADDRESS_MISSING or CRYPTO_REFUND_ADDRESS_INVALID before order creation. Limited to 5 calls per 10 minutes per merchant.
GET /api/v1/integration/statusSandbox or liveOnboarding steps[], each with actor and evidence (webhook registrations, the last delivery's response code, whether live orders can be created), plus verified, complete, liveWebhookReady, nextAction and nextAgentAction.

Check verified, not complete. verified turns true once your sandbox webhook accepts a signed ORDER_FULFILLED delivery. complete tracks the onboarding checklist and turns true with the first live order, whether or not anything was verified. Steps with "actor": "MERCHANT" cannot be done with an API key, so the agent hands them back to you to finish in the dashboard or with peer-pay-cli setup.

Onramp Into User Wallet​

To settle straight to your customer's wallet, set destinationAddress per order. If your server must not be the one that chooses that address, use a checkout grant: the customer enters and confirms the address on Peer's page.

const checkout = await createCheckout(
{
requestedUsdcAmount: '100.00',
destinationChainId: 8453,
destinationToken: 'USDC',
destinationAddress: userWalletAddress,
successUrl: `${process.env.APP_URL}/onramp/success`,
notes: { type: 'onramp', userWallet: userWalletAddress },
},
opts,
);