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

# Stripe Setup

> Configure Stripe for billing and subscription features

# Stripe Setup

HostMetrics uses Stripe for subscription billing. This setup is optional for development if you're not working on billing features.

## 1. Create a Stripe Account

1. Sign up at [stripe.com](https://stripe.com)
2. Stay in **Test Mode** (toggle in the top-right of the dashboard)

## 2. Get API Keys

1. Go to **Developers > API Keys**
2. Copy your **Publishable key** and **Secret key**
3. Add to `.env.local`:

```env theme={null}
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY=pk_test_...
STRIPE_SECRET_KEY=sk_test_...
```

## 3. Set Up Webhook

For local development, use the Stripe CLI:

```bash theme={null}
# Install Stripe CLI
brew install stripe/stripe-cli/stripe

# Login
stripe login

# Forward webhooks to your local server
stripe listen --forward-to localhost:3000/api/stripe/webhook
```

Copy the webhook signing secret and add it:

```env theme={null}
STRIPE_WEBHOOK_SECRET=whsec_...
```

## 4. Create Products and Plans

In the Stripe Dashboard, create subscription products that match your plan tiers. The webhook handler at `/api/stripe/webhook` processes these events:

* `checkout.session.completed` — New subscription
* `customer.subscription.updated` — Plan change
* `customer.subscription.deleted` — Cancellation
* `invoice.paid` — Payment recorded
* `invoice.payment_failed` — Payment failure

<Note>
  If you're not working on billing features, you can skip Stripe setup entirely. The app works without it — billing pages will show errors but other features are unaffected.
</Note>
