# How to render embedded checkout (https://developer.godaddy.com/en/docs/api-users/commerce/accept-payments/online-payments/embedded)

---
title: How to render embedded checkout
description: >-
  Render Unified Checkout inside your own website with a React component, using
  a session your server creates.
keywords: >-
  embedded checkout, Unified Checkout, React checkout, checkout session,
  GoDaddyProvider, Checkout component, website payment form, online payments,
  GoDaddy Payments.
agentNotes:
  permissions:
    - GoDaddy Payments account on the business that owns the store
  scopes:
    - 'commerce.checkout-session:write'
  idempotent: false
  destructive: false
  failureRecovery: >-
    Distinguish two failures. A failure creating the session means your token,
    its scope, the storeId, the order, or the return URLs are wrong, and no
    money has moved. A failure after a valid session exists is a payment failure
    that GoDaddy Payments reports through the checkout interface. Session
    creation isn't idempotent, so calling it again creates another session and
    another draft order. Reuse the session you already hold.
related:
  guides:
    - title: How to create a checkout session
      href: /docs/api-users/commerce/accept-payments/online-payments/create-session
    - title: How to use hosted checkout
      href: /docs/api-users/commerce/accept-payments/online-payments/hosted
    - title: How to configure checkout
      href: /docs/api-users/commerce/accept-payments/online-payments/configure
    - title: How to set up Apple Pay
      href: /docs/api-users/commerce/accept-payments/online-payments/apple-pay
  concepts:
    - title: About online payments
      href: /docs/api-users/commerce/accept-payments/online-payments
    - title: Checkout session reference
      href: /docs/api-users/commerce/accept-payments/online-payments/session-fields
pageId: e3dd3961-bc49-4f91-8e5c-dfd79bc2c72f
---

## 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](https://developer.godaddy.com/docs/api-users/commerce/accept-payments/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](https://developer.godaddy.com/docs/api-users/commerce/accept-payments/online-payments/create-session) to build the server route.

## Add Unified Checkout to your project

The following procedure installs the checkout package and its stylesheet.

1. Install the package:

   ```bash tab="npm"
   npm install @godaddy/react @tanstack/react-query react-hook-form
   ```

   ```bash tab="pnpm"
   pnpm add @godaddy/react @tanstack/react-query react-hook-form
   ```

   ```bash tab="yarn"
   yarn add @godaddy/react @tanstack/react-query react-hook-form
   ```

2. Import the stylesheet once at your application entry point:

   ```typescript
   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:

  ```tsx
  '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                 |                                                                                                                  |

`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.

1. Fetch the session from your endpoint:

   ```tsx
   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} />;
   }
   ```

2. Render the checkout component:

   ```tsx
   import { Checkout, type CheckoutSession } from '@godaddy/react';

   export function CheckoutPage({ session }: { session: CheckoutSession }) {
     return (
       <Checkout session={session} />
     );
   }
   ```

3. (*Optional*) Order the checkout sections by passing `layout`:

   ```tsx
   <Checkout
     session={session}
     layout={['payment', 'contact']}
   />
   ```

   Valid values are `contact`, `payment`, `shipping`, `pickup`, `delivery`, `tips`, `express-checkout`, and `notes`. Checkout appends any you omit after the ones you list.

4. (*Optional*) Require extra fields with a zod schema:

   ```typescript
   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:

   ```tsx
   <Checkout
     session={session}
     checkoutFormSchema={customSchema}
   />
   ```

   `zod` ships 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](https://developer.godaddy.com/docs/api-users/commerce/accept-payments/online-payments/session-fields#checkout-sections) for which sections display and what session flags enable them.

Go to [About online payments](https://developer.godaddy.com/docs/api-users/commerce/accept-payments/online-payments#when-you-learn-the-result) for how you confirm the payment after the shopper returns.

Go to [How to create a checkout session](https://developer.godaddy.com/docs/api-users/commerce/accept-payments/online-payments/create-session#common-errors) for session create error messages and what to change.
