> ## Documentation Index
> Fetch the complete documentation index at: https://docs.priceos.com/llms.txt
> Use this file to discover all available pages before exploring further.

# useCheckout

> Create and open Stripe checkout sessions from React.

The `useCheckout` hook creates checkout sessions using your backend checkout route.
By default it calls `POST /api/priceos/v1/checkout`.

<Tip>
  Setup first: see the [React integration guide](/react-integration).
</Tip>

## Usage

```tsx theme={null}
const { createCheckoutSession, openCheckout } = useCheckout(options?)
```

## Parameters

<ParamField path="options.customerId" type="string">
  Optional fallback `customerId` used when `openCheckout`/`createCheckoutSession` are called without `customerId` in the body.
</ParamField>

## Returns

<ParamField path="createCheckoutSession" type="(body) => Promise<CreateCustomerCheckoutResponse>">
  Creates a checkout session and returns `{ url }`.
</ParamField>

<ParamField path="openCheckout" type="(body) => Promise<CreateCustomerCheckoutResponse>">
  Creates a checkout session, then redirects the browser to Stripe Checkout.
</ParamField>

## Body fields

<ParamField path="productKey" type="string" required>
  Product key from your PriceOS dashboard to start checkout for.
</ParamField>

<ParamField path="stripePriceId" type="string">
  Optional Stripe price ID override. When omitted, PriceOS uses the product's default active Stripe price.
</ParamField>

<ParamField path="successUrl" type="string">
  Optional URL to redirect to when checkout succeeds.
</ParamField>

<ParamField path="cancelUrl" type="string">
  Optional URL to redirect to when checkout is canceled.
</ParamField>

<ParamField path="customerId" type="string">
  Optional customer override. If omitted, the hook uses `options.customerId` or your backend `identifyCustomer`.
</ParamField>

<ParamField path="metadata" type="Record<string, string>">
  Optional metadata to attach to the Stripe checkout session.
</ParamField>

<ParamField path="checkoutParams" type="Record<string, unknown>">
  Optional Stripe Checkout session params to merge into the request.
</ParamField>

## Example

```tsx theme={null}
import { useCheckout } from "priceos/react";

export function UpgradeButton() {
  const { openCheckout } = useCheckout();

  async function onClick() {
    await openCheckout({
      productKey: "starter_monthly",
      successUrl: "https://app.acme.com/settings/billing?checkout=success",
      cancelUrl: "https://app.acme.com/settings/billing?checkout=canceled",
    });
  }

  return <button onClick={onClick}>Upgrade</button>;
}
```
