How to render embedded checkout
View as MarkdownRender Unified Checkout inside your own website with a React component, using a session your server creates.
Overview
Embedded checkout keeps the shopper on your own website. A React component renders the checkout interface in your page, and your server creates the checkout session.
The integration has three parts: a server route that creates the session, a page that fetches it, and a Checkout component that renders the form. The following diagram shows how they connect and which one holds your Personal Access Token (PAT).
The package has a server half and a browser half. Your server imports createCheckoutSession from @godaddy/react/server. Your page imports GoDaddyProvider and Checkout from @godaddy/react. Your PAT never crosses into the browser.
This page covers the embedded form. Go to About online payments for how the payment completes.
Prerequisites
The following prerequisites are required before you can render embedded checkout:
- a React 18 or 19 application
- a server route that creates a checkout session and returns the whole session object, including its
token
Go to How to create a checkout session to build the server route.
Add Unified Checkout to your project
The following procedure installs the checkout package and its stylesheet.
-
Install the package:
npm install @godaddy/react @tanstack/react-query react-hook-form -
Import the stylesheet once at your application entry point:
import '@godaddy/react/styles-tailwind.css';The checkout interface doesn't load its styles without it.
@tanstack/react-query and react-hook-form are peer dependencies the checkout component needs. Projects that don't use Tailwind import @godaddy/react/styles.css instead.
Wrap your app in the provider
Every prop is optional. The following table lists when to use each one:
| Prop | Why supply it | Note |
|---|---|---|
queryClient | To share a query cache and retry settings with the rest of your app | The provider creates its own if you omit this |
apiHost | To route checkout API calls through a different host | Defaults to api.godaddy.com; session create uses a separate host |
storeId, clientId, channelId | To make these identifiers available without reading the session | The session already carries these (never put a secret here) |
appearance | To match checkout colors to your brand | |
locale | To force a specific language regardless of browser settings | Defaults to en-US |
localization | To override individual strings in the checkout form | Types come from @godaddy/localizations, which installs with the package |
debug | To log verbose checkout events during development | |
Link | To navigate checkout links client-side with your router |
These values run in the browser, so read them through your bundler's public environment mechanism. Server-only variables aren't available here.
The following procedure sets up GoDaddyProvider once, wrapping your routes.
-
Create a providers component:
'use client'; import { GoDaddyProvider } from '@godaddy/react'; import { QueryClient } from '@tanstack/react-query'; import { useState } from 'react'; export function Providers({ children }: { children: React.ReactNode }) { // Create the client inside the component so server rendering // doesn't share one client across requests. const [queryClient] = useState( () => new QueryClient({ defaultOptions: { queries: { retry: 1, refetchOnWindowFocus: false }, }, }), ); return ( <GoDaddyProvider apiHost="api.godaddy.com" queryClient={queryClient}> {children} </GoDaddyProvider> ); }
Render checkout
The <Checkout> component takes the session your server created. The following table lists common props and what they do.
| Prop | Purpose | Note |
|---|---|---|
layout | Controls the order sections display in | Checkout appends any you omit after the ones you list. The session decides which sections display, not layout. |
checkoutFormSchema | Applies a zod schema for extra field validation | |
defaultValues | Pre-fills form fields | Only contactEmail is supported |
appearance | Sets theme variables for the checkout form | Overrides values set on the provider. Session appearance values override this prop. |
enableTracking | Emits checkout analytics events |
Don't list a section the session hasn't enabled
layout normally can't make a section display. tips is the exception: listing it while enableTips is unset reserves its row anyway, leaving a visible gap. List tips only when the session enables it.
The following procedure renders the checkout form with optional customizations for layout order and field validation.
-
Fetch the session from your endpoint:
import type { CheckoutSession } from '@godaddy/react'; import { useEffect, useState } from 'react'; export default function Home() { const [session, setSession] = useState<CheckoutSession | null>(null); const [error, setError] = useState<string | null>(null); useEffect(() => { fetch('/api/checkout-session', { method: 'POST' }) .then(async (response) => { const data = await response.json(); if (!response.ok) throw new Error(data.error ?? 'Could not create the session'); return data; }) .then(setSession) .catch((error) => setError(error.message)); }, []); if (error) return <p>{error}</p>; if (!session) return <p>Creating checkout session…</p>; return <CheckoutPage session={session} />; } -
Render the checkout component:
import { Checkout, type CheckoutSession } from '@godaddy/react'; export function CheckoutPage({ session }: { session: CheckoutSession }) { return ( <Checkout session={session} /> ); } -
(Optional) Order the checkout sections by passing
layout:<Checkout session={session} layout={['payment', 'contact']} />Valid values are
contact,payment,shipping,pickup,delivery,tips,express-checkout, andnotes. Checkout appends any you omit after the ones you list. -
(Optional) Require extra fields with a zod schema:
import { z } from 'zod'; import type { CheckoutFormSchema } from '@godaddy/react'; const customSchema: CheckoutFormSchema = { shippingPhone: z.string().min(1, 'Phone number is required'), };Then pass the schema to the component:
<Checkout session={session} checkoutFormSchema={customSchema} />zod is included
zodships as a dependency of@godaddy/react. Install it directly if your package manager doesn't hoist dependencies.
A declined or failed payment shows an error in the checkout form, and the shopper might retry there.
Go to Checkout session reference for which sections display and what session flags enable them.
Go to About online payments for how you confirm the payment after the shopper returns.
Go to How to create a checkout session for session create error messages and what to change.
Last updated on
How is this guide?