feat: Wire Stripe checkout for Pro/Elite subscriptions#89
Conversation
New API routes (Next.js, no Python backend dependency): - /api/checkout: Creates Stripe checkout session for Pro ($19) or Elite ($49) - /api/webhooks/stripe: Handles subscription lifecycle events Implementation: - Looks up prices by product ID at runtime (no price ID config needed) - Product IDs hardcoded: prod_Ta3YZOPq86bM2J (Pro), prod_Ta3aXZCqBcoFnI (Elite) - Creates Stripe customer on first checkout, links to Supabase profile - Webhook updates subscription_tier, subscription_status in profiles table - Handles: checkout.session.completed, subscription.updated/deleted, invoice.payment_failed - Uses Supabase service role key for webhook (no user session available) Also: - Updated pricing page to call /api/checkout (was calling Python backend) - Added stripe server SDK to package.json - Updated .env.example with all required Stripe + Supabase vars Requires Vercel env vars: STRIPE_SECRET_KEY, NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY, SUPABASE_SERVICE_ROLE_KEY, STRIPE_WEBHOOK_SECRET (after deploy) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (5)
📝 WalkthroughWalkthroughThis change integrates Stripe payment processing into the application by adding environment configuration for Stripe credentials and product IDs, implementing API endpoints for checkout session creation and webhook event handling, and updating the pricing page to use the new internal checkout endpoint. Changes
Sequence Diagram(s)sequenceDiagram
actor User
participant Pricing as Pricing Page
participant CheckoutAPI as /api/checkout
participant Supabase
participant Stripe
User->>Pricing: Click upgrade to tier
Pricing->>CheckoutAPI: POST /api/checkout {tier, user_id, user_email}
CheckoutAPI->>CheckoutAPI: Validate tier & credentials
CheckoutAPI->>Supabase: Query profiles for stripe_customer_id
alt No existing customer
CheckoutAPI->>Stripe: Create customer
Stripe-->>CheckoutAPI: customer_id
CheckoutAPI->>Supabase: Update profiles with customer_id
end
CheckoutAPI->>Stripe: List recurring prices for product
CheckoutAPI->>Stripe: Create checkout session
Stripe-->>CheckoutAPI: session {url, id}
CheckoutAPI-->>Pricing: Return session URL
Pricing-->>User: Redirect to Stripe checkout
sequenceDiagram
participant Stripe as Stripe (Events)
participant WebhookAPI as /webhooks/stripe
participant WebhookAPI as Webhook Handler
participant Supabase as Supabase
Stripe->>WebhookAPI: POST with event + stripe-signature
WebhookAPI->>WebhookAPI: Verify signature
alt Signature invalid
WebhookAPI-->>Stripe: 400 Bad Request
end
alt checkout.session.completed
WebhookAPI->>Supabase: Update subscription_tier, status=active
else customer.subscription.updated
WebhookAPI->>Supabase: Map product to tier, update status & dates
else customer.subscription.deleted
WebhookAPI->>Supabase: Set tier=free, status=canceled, ends_at
else invoice.payment_failed
WebhookAPI->>Supabase: Set status=past_due, log warning
end
WebhookAPI-->>Stripe: 200 {received: true}
Estimated Code Review Effort🎯 4 (Complex) | ⏱️ ~55 minutes Poem
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
/api/checkoutroute: creates Stripe checkout sessions for Pro ($19) and Elite ($49)/api/webhooks/striperoute: handles subscription lifecycle (created, updated, deleted, payment failed)Env vars needed on Vercel
STRIPE_SECRET_KEYNEXT_PUBLIC_STRIPE_PUBLISHABLE_KEYSUPABASE_SERVICE_ROLE_KEYSTRIPE_WEBHOOK_SECRET(after deploy, from Stripe webhook setup)Post-merge setup
https://deepstack.trade/api/webhooks/stripecheckout.session.completed,customer.subscription.updated,customer.subscription.deleted,invoice.payment_failedTest plan
Generated with Claude Code
Summary by CodeRabbit
New Features