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

# Stripe

## Setting up Stripe

### API Keys

```bash web/.env theme={null}
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY=
STRIPE_SECRET_KEY=
```

To get your Stripe API keys:

1. Create a [Stripe account](https://dashboard.stripe.com/register)
2. Go to the [Developers section](https://dashboard.stripe.com/test/developers) in your Stripe Dashboard
3. Under "API keys" you'll find both your publishable and secret keys

* For development, use the test mode keys
* For production, switch to live mode to get production keys

### Webhook Setup

Webhooks are essential for handling Stripe events (successful payments, subscription updates, etc.).

1. Install the [Stripe CLI](https://stripe.com/docs/stripe-cli) to get your webhook secret

2. Login to the Stripe CLI:

```bash theme={null}
stripe login
```

3. Open a new terminal and start listening for webhooks:

```bash theme={null}
cd app
pnpm stripe:listen
```

This command will output your webhook signing secret - copy it to

```bash web/.env theme={null}
STRIPE_WEBHOOK_SECRET=
```

## Products and Prices Setup

### Creating Products

1. Go to [Products](https://dashboard.stripe.com/test/products) in your Stripe Dashboard
2. Click "Add product"
3. Create two products (example):

* Starter Plan
* Pro Plan

### Setting Up Prices

For each product, you'll need to create multiple prices:

```bash web/.env theme={null}
# Stripe Subscriptions
NEXT_PUBLIC_STRIPE_STARTER_MONTHLY_PRICE_ID=
NEXT_PUBLIC_STRIPE_STARTER_ANNUALLY_PRICE_ID=
NEXT_PUBLIC_STRIPE_PRO_MONTHLY_PRICE_ID=
NEXT_PUBLIC_STRIPE_PRO_ANNUALLY_PRICE_ID=

# Stripe Onetime Payments
NEXT_PUBLIC_STRIPE_STARTER_ONETIME_PRICE_ID=
NEXT_PUBLIC_STRIPE_PRO_ONETIME_PRICE_ID=
```

For each product:

1. Click "Add price"
2. Create recurring prices:

* Monthly subscription (e.g., \$9/month)
* Annual subscription (e.g., \$90/year)

3. Create one-time prices if needed
4. Copy the price IDs to your `.env`

### Price ID Location

To find your price IDs:

1. Go to [Products](https://dashboard.stripe.com/test/products)
2. Click on a product
3. Under "Pricing", you'll see all prices for that product
4. Click the "..." menu next to each price
5. Select "Copy ID" - it will look like `price_XXXXXXXXXXXXXXXXX`

## Webhooks

Webhooks are essential for handling Stripe events (successful payments, subscription updates, etc.).

1. Open webhooks in the Stripe Dashboard

2. Click "Add webhook"

3. Set your webhook URL to:
   `https://yourdomain.com/api/webhooks/stripe`

4. Add the following events:

```bash theme={null}
checkout.session.completed
```

```bash theme={null}
customer.subscription.deleted
```

```bash theme={null}
customer.subscription.updated
```

```bash theme={null}
invoice.paid
```

```bash theme={null}
payment_intent.succeeded
```

## Testing

Use Stripe's test cards for payments:

* Success: `4242 4242 4242 4242`
* Decline: `4000 0000 0000 0002`
* Use any future date for expiry and any 3 digits for CVC

See [Stripe Testing](https://docs.stripe.com/testing) for more information.

## Going Live

Before going live:

1. Complete Stripe's account activation process
2. Switch to live mode in the Stripe Dashboard
3. Update your environment variables with live mode keys
4. Set up production webhooks
5. Test the entire payment flow in live mode with a real card (use a small amount)
6. Monitor your [Stripe Dashboard](https://dashboard.stripe.com) for real transactions

## Common Issues

* Webhook errors: Ensure your webhook endpoint is accessible and the signing secret is correct
* Payment failures: Check the [Events](https://dashboard.stripe.com/test/events) section in Stripe Dashboard
* Price ID issues: Verify you're using the correct price IDs for test/live mode in combination with the correct stripe keys
