Setup & Configuration

This docs guides you through configuring Stripe with environment variables and initializing the Stripe client.

To use Stripe, you must set up API keys and webhook secrets in your .env file, validated by t3-env to ensure the app starts without errors. These configurations enable payment processing and subscription management in your lib/stripe folder.

Steps to Set Up Stripe

Create a Stripe Account

  • Sign up at Stripe and create a new account.
  • Access the Stripe dashboard to obtain API keys.

Obtain Stripe API Keys

  • Navigate to Developers > API Keys in the Stripe dashboard.
  • Copy the Publishable Key (starts with pk_), Secret Key (starts with sk_), and Webhook Secret (starts with whsec_) for your project.

Configure Environment Variables

  • Add these to your .env (or .env.local) file:
Env VariableTypeDefault
STRIPE_SECRET_KEY
string
sk_test_xxxx
STRIPE_PUBLISHABLE_KEY
string
pk_test_xxxx
STRIPE_WEBHOOK_SECRET
string
whsec_xxxx
  • Ensure .env is in .gitignore to protect sensitive keys.

Verify Configuration

  • Run npm run dev to validate keys via t3-env (in env.mjs).
  • If validation fails, confirm the keys in the Stripe dashboard.

Set Up Products and Pricing

  • In the Stripe dashboard, create products under Products to define items or subscription plans.
  • Configure pricing details to populate the pricing section in your app.

For advanced setup options, such as custom checkout flows, consult the Stripe Documentation.

How is this guide ?

Last updated on