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 withsk_), and Webhook Secret (starts withwhsec_) for your project.
Configure Environment Variables
- Add these to your
.env(or.env.local) file:
| Env Variable | Type | Default |
|---|---|---|
STRIPE_SECRET_KEY | string | sk_test_xxxx |
STRIPE_PUBLISHABLE_KEY | string | pk_test_xxxx |
STRIPE_WEBHOOK_SECRET | string | whsec_xxxx |
- Ensure
.envis in.gitignoreto protect sensitive keys.
Verify Configuration
- Run
npm run devto validate keys viat3-env(inenv.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