Skip to main content
Full working examples using the Checkout API and @withlocus/checkout-react. Create sessions on your server, then render checkout on the client.

Install

Use the Checkout API on your server to create sessions. Use @withlocus/checkout-react on the client to render checkout. Requires React 17+.

Quick start (without receipt)

Step 1: Create a session

There is no separate server-side npm package for checkout session creation. Call POST https://api.paywithlocus.com/api/checkout/sessions from your server with your Locus API key.

Step 2: Render checkout

Pass the session ID to the LocusCheckout component on the client.

Full example (Next.js)

A complete Next.js flow — API route creates the session, page renders the checkout.

With receipt

Pass receiptConfig in the request body when you create the session to attach line items, tax, and company info. The client-side LocusCheckout component stays exactly the same. It automatically renders receipt details when the session has them.

Create a session with receipt

Render checkout

The LocusCheckout component is identical whether the session uses receipts or not. All receipt configuration happens in your POST /checkout/sessions request.

receiptConfig fields

After payment, receipt details also appear in the buyer’s Purchases tab on the Locus dashboard.

Display modes

The mode prop controls how the checkout UI appears.

Embedded

Renders inline in your page. Best for dedicated checkout pages.
Opens checkout in a centered popup window. Calls onCancel if the popup is closed.

Redirect

Navigates the browser to the hosted checkout page. Renders nothing.

Using the hook

For custom checkout buttons or non-standard flows, use useLocusCheckout instead of the LocusCheckout component.
The hook gives you openPopup, redirectToCheckout, and getCheckoutUrl — see the full API in the Merchant Integration reference.