Skip to main content
The @lavapayments/checkout package provides a React hook for embedding Lava’s checkout flow as a full-screen iframe overlay. It handles the complete payment flow — phone verification, payment setup, and subscription creation.

Installation

Requirements: React 16.8+ (hooks support)

How It Works

Checkout is a two-step flow:
  1. Your backend creates a checkout session using the Node.js SDK, which returns a checkout_session_token
  2. Your frontend passes that token to open(), which renders the checkout as a full-screen iframe overlay
Your secret key is never exposed to the browser — session creation always happens server-side.

Checkout Modes

The checkout mode is set when creating the session on your backend, not in the React hook. See Checkout for full details on each mode.

useLavaCheckout

The SDK exports a single hook: useLavaCheckout. It returns an open function that launches the checkout iframe.
All callbacks are optional.
onSuccess is the easiest way to capture the customerId, but the user can close their browser before it fires. For reliable server-side capture, use the customer.created webhook. In production, use both: the callback for instant UI feedback, the webhook for backend persistence.

Behavior

  • open() renders a full-screen fixed iframe (z-index: 2147483647) over your app
  • The iframe is sandboxed with allow-forms allow-scripts allow-same-origin
  • A beforeunload handler warns users if they try to navigate away mid-checkout
  • The iframe is automatically removed when checkout completes or is cancelled

Full Example

1. Backend — create a checkout session (Next.js route handler)

Use the @lavapayments/nodejs SDK to create a session. The SDK returns a checkout_session_token that you pass to your frontend.

2. Frontend — open checkout with the session token

Next Steps

Checkout Guide

Detailed guide on checkout modes, completion handling, and webhooks

Node.js SDK

Server-side SDK for creating checkout sessions and managing resources