Skip to main content

Redirect Functions

Helpers for generating and navigating to checkout URLs.

getCheckoutUrl

Builds a checkout URL without redirecting.

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

Example

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

const checkout = await createCheckout(params, opts);

const url = getCheckoutUrl(checkout.order.id, checkout.orderToken, {
apiBaseUrl: 'https://api.pay.peer.xyz',
checkoutBaseUrl: 'https://pay.peer.xyz',
apiKey: process.env.ZKPAY_API_KEY!,
});

console.log(url);
// https://pay.peer.xyz/?order=ord_...&token=...

redirectToCheckout

Immediately redirects the browser to checkout.

function redirectToCheckout(
orderId: string,
orderToken: string,
opts: CheckoutClientOptions
): void
import { redirectToCheckout } from '@zkp2p/pay-sdk';

redirectToCheckout(orderId, orderToken, {
apiBaseUrl: 'https://api.pay.peer.xyz',
checkoutBaseUrl: 'https://pay.peer.xyz',
apiKey: process.env.ZKPAY_API_KEY!,
});

createCheckoutAndRedirect

Creates an order and redirects in one call.

function createCheckoutAndRedirect(
params: CreateOrderRequest,
opts: CheckoutClientOptions
): Promise<CreateCheckoutResult>
import { createCheckoutAndRedirect } from '@zkp2p/pay-sdk';

await createCheckoutAndRedirect(
{
requestedUsdcAmount: '50.00',
destinationChainId: 8453,
destinationToken: 'USDC',
},
{
apiBaseUrl: 'https://api.pay.peer.xyz',
checkoutBaseUrl: 'https://pay.peer.xyz',
apiKey: process.env.ZKPAY_API_KEY!,
}
);
  1. Create an order on your backend.
  2. Store order.id in your order system for reconciliation.
  3. Redirect to checkoutUrl.