Skip to content

ketankauntia/stripe-payment-integration

Repository files navigation

Dodo Payments Boilerplate (Next.js + Firebase + Stripe)

Demo Video

▶️ Watch the demo

Rough Design plan (before starting)

image

Quickstart

  1. Install deps

    pnpm i   # or npm/yarn
  2. Copy envs

    cp .env.local.example .env.local
    cp functions/.env.example functions/.env
    # Fill Firebase client keys and Stripe test keys + price IDs
  3. Start local dev (3 terminals)

    pnpm emulators
    pnpm dev
    pnpm stripe:listen
  4. Try the flow

    • Visit /login → sign up
    • Go to /pricing → choose Pro Monthly
    • Pay with 4242 4242 4242 4242
    • Redirect to /dashboard → see plan & dates
    • Firestore users/ updated; Stripe CLI shows webhooks

Configuration

  • Change Firebase project once in package.json → config.project
  • Prices: set STRIPE_PRICE_* in functions/.env
  • Add a new plan:
    • functions/src/plans.server.ts → add key
    • lib/planCatalog.ts → add label

Functions

  • health: GET /asia-south1/health → { ok: true, stripe: boolean }
  • stripeWebhook: signature-verified
  • createCheckoutSession: uses plan code → env price id
  • billingPortal: manage subscription

Firestore Rules

The firestore.rules file ensures users can only access their own documents in /users/{userId}. Deploy with:

firebase deploy --only firestore:rules

Test webhooks

  • Uses pnpm stripe:listen forwarding to /stripeWebhook
  • Note on replacing STRIPE_WEBHOOK_SECRET when using "stripe listen"

Assumptions & Trade-offs

  • Assumptions :
   - user isn't signed up, so we make him signup
   - initially user is in the free plan ( didnt show it on ui, was showing, but messed it a bit later)
   - only upon successful transcation is the firestore entry is updated with a pro plan with plan details
   - Plans are fixed in env
   - Minimal ui : generated by gpt, refiened + refactored it a little   
  • Trade-offs :
   - didnt store the plans in db, instead stored in env
   - rest of the things below are gpt generated :
      - Firestore user plans update only via Stripe webhook events, so, firestore may lag for a few seconds after checkout.
      - Firestore rules are minimal (user can only read/write own doc).
      - No advanced error handling

Troubleshooting

  • make sure you run the last 3 scripts one after the other.
  • make sure you have configured your credentials properly
  • make sure to have added firestore rules
  • 403 on Firestore: deploy rules or sign in
  • 400 on checkout: missing STRIPE_PRICE_* env
  • No webhook events: stripe listen not running / wrong secret
  • CORS/URL issues: check NEXT_PUBLIC_FUNCTIONS_URL and APP_URL

Scripts

  • pnpm emulators
  • pnpm dev
  • pnpm stripe:listen
  • pnpm build:functions
  • pnpm deploy:functions

About

integrated stripe payments with firebase :)

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors