Skip to content

Davidasix/stripe integration#8

Merged
DavidASix merged 17 commits into
mainfrom
davidasix/stripe-integration
Jun 29, 2025
Merged

Davidasix/stripe integration#8
DavidASix merged 17 commits into
mainfrom
davidasix/stripe-integration

Conversation

@DavidASix

Copy link
Copy Markdown
Owner

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

  • Added a new SubscriptionPage component in src/app/(product)/subscription/page.tsx to display the user's subscription status, calculate remaining days, and provide a "Subscribe Now" button that redirects to a Stripe checkout session.
  • Updated PricingOptions in src/components/common/pricing-options.tsx to remove inline checkout logic and redirect users to the subscription page for subscribing. [1] [2] [3]

API Endpoints

  • Added a GET endpoint in src/app/api/purchases/check-active-subscription/route.ts to check if a user has an active subscription using the withActiveSubscription middleware.
  • Added a webhook handler in src/app/api/purchases/webhook/route.ts to process Stripe events like checkout.session.completed and invoice.payment_succeeded, updating user records and logging subscription payments.

Middleware

  • Introduced withActiveSubscription middleware in src/middleware/withActiveSubscription.ts to check if a user has an active subscription based on the subscription_payments table.

Database Schema

  • Added a stripe_customer_id column to the user table and created a new subscription_payments table to track subscription payments. These changes were implemented in the migration file src/schema/migrations/0007_fantastic_jazinda.sql.
  • Updated the users table schema in src/schema/schema.ts to include the new stripe_customer_id column.

Refactoring and Updates

  • Renamed the checkout endpoint URL in src/app/api/purchases/initialize-checkout/schema.ts from /checkout-context to /initialize-checkout.
  • Updated the success and cancel URLs in the Stripe checkout session to point to the subscription page instead of the purchases page.
  • Adjusted the price_id for the "All Access" product in src/lib/products.ts to dynamically switch between development and production environments.

@DavidASix
DavidASix requested a review from Copilot June 29, 2025 18:40

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_id on user and a new subscription_payments table, plus migrations.
  • Implement withActiveSubscription middleware and a check-active-subscription API endpoint.
  • Add Stripe webhook handler to record payments and new SubscriptionPage UI, 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-subscription endpoint 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(

Comment thread src/middleware/withActiveSubscription.ts Outdated
@DavidASix
DavidASix force-pushed the davidasix/stripe-integration branch from 502feda to 890de00 Compare June 29, 2025 19:05
@DavidASix
DavidASix merged commit 7b57115 into main Jun 29, 2025
2 checks passed
@DavidASix
DavidASix deleted the davidasix/stripe-integration branch July 27, 2025 21:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants