@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
How It Works
Checkout is a two-step flow:- Your backend creates a checkout session using the Node.js SDK, which returns a
checkout_session_token - Your frontend passes that token to
open(), which renders the checkout as a full-screen iframe overlay
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.| Mode | Purpose | Required Params |
|---|---|---|
subscription | Subscribe to a recurring plan | subscription_config_id |
credit_bundle | Buy a fixed credit pack | connection_id, credit_bundle_id |
useLavaCheckout
The SDK exports a single hook:useLavaCheckout. It returns an open function that launches the checkout iframe.
onSuccess is the easiest way to capture the connectionId, but the user can close their browser before it fires. For reliable server-side capture, use the connection.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
beforeunloadhandler 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.