Stripe

Configure stripe with a single click

Usage

npx next-inject add stripe

Setup Stripe Keys

  1. Visit your stripe dashboard.
  2. On your dashboard, you should be able to copy the live Publishable key and Secret key.
  3. Toggle "test mode", and copy the test Publishable key and Secret key.
  4. Copy both the live and test keys into your .env.local file as follows:
.env.local
# Stripe (local)
STRIPE_PUBLIC_TEST_KEY=TEST_PUBLIC_KEY
STRIPE_SECRET_TEST_KEY=TEST_SECRET_KEY
 
# Stripe (prod)
STRIPE_PUBLIC_KEY=PUBLIC_KEY
STRIPE_SECRET_KEY=SECRET_KEY

Create a Product

  1. Visit the products section of stripe and create your first product.
  2. Once created, click on your product, and click the three dots under the Pricing section to Copy price ID.
  3. Inside your project, go to src/lib/stripe.ts and paste your price ID here:
src/lib/stripe.ts
export const prices = isLiveMode
  ? ({
      // ! Live Price Ids
      oneOff: "price_YOUR_PRICE",
      subscription: "price_YOUR_SUBSCRIPTION_PRICE",
    } as const)
  : ({
      // ! Test Price Ids
      oneOff: "price_YOUR_TEST_PRICE",
      subscription: "price_YOUR_TEST_SUBSCRIPTION_PRICE",
    } as const)

Configure Webhooks

  1. Follow these instructions to setup and log in to the Stripe CLI
  2. Now run the following command in your terminal:
stripe listen --forward-to localhost:3000/api/webhooks/stripe
  1. Copy the Signing Secret that appears in your terminal window into your .env.local file:
.env.local
STRIPE_WEBHOOK_TEST_SECRET=TEST_WEBHOOK_SECRET
  1. Visit the stripe webhooks page and select "Add endpoint"
  2. Set your production domain name as the endpoint URL appended with /api/webhooks/stripe:

E.g. https://example.com/api/webhooks/stripe

  1. Copy the Signing Secret into .env.local:
.env.local
STRIPE_WEBHOOK_SECRET=WEBHOOK_SECRET
  1. Here is how the final .env.local file should look:
.env.local
# Stripe (local)
STRIPE_PUBLIC_TEST_KEY=TEST_PUBLIC_KEY
STRIPE_SECRET_TEST_KEY=TEST_SECRET_KEY
STRIPE_WEBHOOK_TEST_SECRET=TEST_WEBHOOK_SECRET
 
# Stripe (prod)
STRIPE_PUBLIC_KEY=PUBLIC_KEY
STRIPE_SECRET_KEY=SECRET_KEY
STRIPE_WEBHOOK_SECRET=WEBHOOK_SECRET
Bonus Features
Seamless switching between live mode and test mode
Demo components for subscriptions and one-time payments

Any further questions?
Please do not hesitate to contact us by email or twitter
Also, If you are enjoying Next Inject, feel free to share a testimonial here!

On this page