.env · generator · Stripe

Stripe .env Generator

Stripe ships three keys per environment — publishable, secret, and webhook signing. This generator produces a .env block with the right prefixes (sk_test_, pk_test_, whsec_) and comments so you don't accidentally mix test and live values.

.env for Stripe · 4 keys
Customize →
STRIPE_SECRET_KEY=sk_test_
STRIPE_PUBLISHABLE_KEY=pk_test_
STRIPE_WEBHOOK_SECRET=whsec_
STRIPE_PRICE_ID_PRO=price_

Secrets regenerate on every page load. Want to combine stacks (e.g., Next.js + Stripe + Supabase)? Use the full generator.

How to use this .env in Stripe

  1. 1.Paste the block into your project's .env or .env.local.
  2. 2.Swap the test prefixes (sk_test_, pk_test_) for live (sk_live_, pk_live_) only in production.
  3. 3.Set STRIPE_WEBHOOK_SECRET to the value Stripe shows when you create the webhook endpoint — it's unique per endpoint.
  4. 4.Never prefix STRIPE_SECRET_KEY with NEXT_PUBLIC_ or VITE_ — it would ship to the browser.

Gotchas

  • Webhook signing secrets are per-endpoint, not per-account. Each webhook URL gets its own whsec_.
  • Rotating a secret key invalidates it immediately — coordinate with any long-running jobs first.
  • Stripe's CLI uses a separate restricted key; add STRIPE_API_KEY for local forward runs if needed.

Common keys explained

STRIPE_SECRET_KEY

Server-only. sk_test_ for dev, sk_live_ for prod.

STRIPE_PUBLISHABLE_KEY

Safe to expose to the browser. Prefix with NEXT_PUBLIC_ or VITE_ if needed.

STRIPE_WEBHOOK_SECRET

whsec_... — unique per webhook endpoint. Used by stripe.webhooks.constructEvent().

STRIPE_PRICE_ID_PRO

price_... — optional but convention for tying price IDs to env.

Related tools

Other stacks