Davidasix/stripe integration#8
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
Adds end-to-end subscription management via Stripe, including database schema changes, middleware and API endpoints for checking subscriptions, webhook handling, and updated UI components for subscription flows.
- Extend database with
stripe_customer_idonuserand a newsubscription_paymentstable, plus migrations. - Implement
withActiveSubscriptionmiddleware and acheck-active-subscriptionAPI endpoint. - Add Stripe webhook handler to record payments and new
SubscriptionPageUI, refactoring checkout initialization and price selection.
Reviewed Changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/schema/schema.ts | Add stripe_customer_id to users and subscription_payments table |
| src/schema/migrations/0007_fantastic_jazinda.sql & meta updates | Migration to alter user and create subscription_payments |
| src/middleware/withActiveSubscription.ts | Middleware to enforce and expose active subscription |
| src/lib/products.ts | Dynamically select price_id based on environment |
| src/components/common/pricing-options.tsx | Updated pricing UI to link to /subscription page |
| src/app/api/purchases/initialize-checkout/schema.ts & route.ts | Rename endpoint to /initialize-checkout and update redirect URLs |
| src/app/api/purchases/check-active-subscription/schema.ts & route.ts | Schema and handler for check-active-subscription API |
| src/app/api/purchases/webhook/route.ts | Webhook endpoint for Stripe events |
| src/app/(product)/subscription/page.tsx | New SubscriptionPage client component |
Comments suppressed due to low confidence (2)
src/app/api/purchases/webhook/route.ts:21
- The webhook handlers for Stripe events (e.g.,
checkout.session.completed) currently lack automated tests. Consider adding unit or integration tests to validate that errors, retries, and database updates behave correctly.
const handleCheckoutSessionCompleted: Handler = async ({ type, data }) => {
src/app/api/purchases/check-active-subscription/route.ts:16
- The
check-active-subscriptionendpoint is critical for guarding feature access but doesn't appear to have any tests. Adding API tests would help ensure correct JSON structure and error handling.
export const GET: RequestHandler<NextRouteContext> = withAuth(
DavidASix
force-pushed
the
davidasix/stripe-integration
branch
from
June 29, 2025 19:05
502feda to
890de00
Compare
This was referenced Jun 29, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request introduces a subscription management feature, including a subscription page, API endpoints, middleware, and database updates. It also refactors existing code to integrate with the new subscription system. Below are the most important changes grouped by theme:
Subscription Page and User Interface
SubscriptionPagecomponent insrc/app/(product)/subscription/page.tsxto display the user's subscription status, calculate remaining days, and provide a "Subscribe Now" button that redirects to a Stripe checkout session.PricingOptionsinsrc/components/common/pricing-options.tsxto remove inline checkout logic and redirect users to the subscription page for subscribing. [1] [2] [3]API Endpoints
GETendpoint insrc/app/api/purchases/check-active-subscription/route.tsto check if a user has an active subscription using thewithActiveSubscriptionmiddleware.src/app/api/purchases/webhook/route.tsto process Stripe events likecheckout.session.completedandinvoice.payment_succeeded, updating user records and logging subscription payments.Middleware
withActiveSubscriptionmiddleware insrc/middleware/withActiveSubscription.tsto check if a user has an active subscription based on thesubscription_paymentstable.Database Schema
stripe_customer_idcolumn to theusertable and created a newsubscription_paymentstable to track subscription payments. These changes were implemented in the migration filesrc/schema/migrations/0007_fantastic_jazinda.sql.userstable schema insrc/schema/schema.tsto include the newstripe_customer_idcolumn.Refactoring and Updates
src/app/api/purchases/initialize-checkout/schema.tsfrom/checkout-contextto/initialize-checkout.price_idfor the "All Access" product insrc/lib/products.tsto dynamically switch between development and production environments.