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

# Next.js adapter

> @sleetpay/nextjs: route handlers for checkout, the billing portal, entitlements and verified webhooks.

`@sleetpay/nextjs` gives you four route handlers for the App Router (any runtime with `Request` and `Response`). It has no dependency on `next` and needs `@sleetpay/sdk`.

```bash theme={null}
npm install @sleetpay/nextjs @sleetpay/sdk
```

```ts lib/sleetpay.ts theme={null}
import { SleetPay } from "@sleetpay/nextjs";
export const sleetpay = new SleetPay({ apiKey: process.env.SLEETPAY_API_KEY! });
```

```ts lib/customer.ts theme={null}
// Resolve the signed-in user on the server (session cookie, JWT, ...)
export const getCustomer = async (req: Request) => {
  const user = await getUserFromSession(req);
  return user ? { externalCustomerId: user.id, email: user.email, name: user.name } : null;
};
```

```ts app/api/checkout/route.ts theme={null}
import { Checkout } from "@sleetpay/nextjs";
export const GET = Checkout({
  sleetpay, getCustomer,
  successUrl: "https://yourapp.com/welcome?checkout={CHECKOUT_ID}", // absolute https URL
  allowedProducts: ["prod_..."],                                    // recommended
});
```

```ts app/api/portal/route.ts theme={null}
import { CustomerPortal } from "@sleetpay/nextjs";
export const GET = CustomerPortal({ sleetpay, getCustomer });
```

```ts app/api/entitlements/route.ts theme={null}
import { CustomerState } from "@sleetpay/nextjs";
export const GET = CustomerState({ sleetpay, getCustomer });
```

```ts app/api/webhook/route.ts theme={null}
import { Webhooks } from "@sleetpay/nextjs";
export const POST = Webhooks({
  secret: process.env.SLEETPAY_WEBHOOK_SECRET!,
  handlers: { "customer.state_changed": async ({ data }) => { /* sync entitlements */ } },
});
```

Link to checkout as `/api/checkout?productId=prod_...`. Optional query parameters: `priceId`, `seats`, `discountId`, `currency` and `metadata` (JSON, flat values only).

> [!NOTE]
>
> **Identity is never read from the query.** The customer always comes from `getCustomer`, so a visitor cannot check out as someone else.

Webhooks verify the signature on the raw body (403 for a bad or stale one) and answer 500 if your handler throws, so the delivery is retried. De-duplicate on the `webhook-id` header if your handler is not idempotent. See [Webhooks](https://docs.sleetpay.com/guides/webhooks.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.