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

# Payments with Stripe

> Configure Stripe Checkout and webhooks for premium activation.

# Payments with Stripe

Stripe is optional. When configured, users can start a Stripe Checkout flow from the app.

## Required variables

```bash theme={null}
VITE_STRIPE_PUBLISHABLE_KEY=
STRIPE_SECRET_KEY=
STRIPE_WEBHOOK_SECRET=
STRIPE_PRICE_ID=
```

For premium activation after payment, also configure Supabase:

```bash theme={null}
VITE_SUPABASE_URL=
VITE_SUPABASE_ANON_KEY=
SUPABASE_SECRET_KEY=
```

Prefer `SUPABASE_URL`, `SUPABASE_PUBLISHABLE_KEY`, and `SUPABASE_SECRET_KEY` for server configuration. Legacy names remain supported during migration.

## Functions

```text theme={null}
netlify/functions/create-checkout-session.ts
netlify/functions/stripe-webhook.ts
```

`create-checkout-session.ts` creates a one-time Stripe Checkout session. When Supabase is enabled, it requires a valid access token; user identity, email, and Price ID are derived by the server.

`stripe-webhook.ts` verifies the signature, payment state, and purchased Price ID before invoking an idempotent database transaction that records payment and activates Premium. Guest support payments remain available for self-hosted deployments without Supabase, but do not grant Premium.

## Stripe dashboard setup

1. Create a Stripe product.
2. Create a one-time price.
3. Set the Price ID only in the trusted server variable `STRIPE_PRICE_ID`.
4. Add your publishable key and secret key to the correct environments.
5. Create a webhook endpoint for:

```text theme={null}
https://your-site.netlify.app/.netlify/functions/stripe-webhook
```

6. Subscribe the endpoint to `checkout.session.completed`.
7. Store the webhook signing secret in `STRIPE_WEBHOOK_SECRET`.

## Local webhook testing

Use the Stripe CLI if you want to test webhooks locally:

```bash theme={null}
stripe listen --forward-to localhost:8888/.netlify/functions/stripe-webhook
```

Run the app through Netlify Dev while testing functions:

```bash theme={null}
npm run dev:full
```
