feat(billing): gate billing page behind feature flag#914
Conversation
Implements Stripe subscription billing using Better Auth's Stripe plugin. ## Backend - Add @better-auth/stripe and stripe packages - Configure Stripe plugin with org-based subscriptions - Add organization hooks: afterCreateOrganization (create Stripe customer), afterUpdateOrganization (sync name), beforeAddMember (seat limit check), afterAddMember/afterRemoveMember (update subscription quantity) - Add plan to session via customSession plugin - Create subscriptions table migration - Add stripeCustomerId to organizations schema ## Frontend - Update billing UI to use cancelAt instead of cancelAtPeriodEnd - Show renewal date for active Pro subscriptions - Add billing pre-warning when inviting members on Pro plan - Add billing note to remove member confirmation on Pro plan - Add toast notification on plan restore - Create billing success page for web app ## Scripts - Add backfill-stripe-customers script for existing orgs - Add recover-stripe-customers script to link orphaned customers - Add wipe-stripe-customers script for dev cleanup ## Environment - Add STRIPE_SECRET_KEY and STRIPE_WEBHOOK_SECRET env vars
Add STRIPE_SECRET_KEY, STRIPE_WEBHOOK_SECRET, STRIPE_PRO_MONTHLY_PRICE_ID, and STRIPE_PRO_YEARLY_PRICE_ID to deploy-preview.yml and deploy-production.yml for api, web, marketing, and admin jobs.
- Remove verbose/lifecycle console.logs from auth server - Remove unused onEvent webhook handler - Fix stale session.plan usage in MembersSettings (use subscription query) - Remove trialing status checks (not used) - Remove unnecessary memberCount || 1 fallback - Remove comments from PlansComparison
- Update @sentry/nextjs to ^10.36.0 across all apps - Align better-auth to ^1.4.17 across all packages - Regenerate bun.lock to fix rollup version mismatch
Hide billing page from users without @superset.sh email until Stripe account is fully configured with tax ID and payment methods.
|
Caution Review failedThe pull request is closed. 📝 WalkthroughWalkthroughIntroduces comprehensive Stripe billing integration across the monorepo, including environment configuration, database schema for subscriptions, updated auth server plugins with organization lifecycle hooks, and refactored desktop/web billing UI components with subscription-aware features, member limits, upgrade/downgrade/cancel flows, and feature-flag gating. Changes
Sequence Diagram(s)sequenceDiagram
actor User
participant Desktop as Desktop App
participant AuthServer as Auth Server
participant Stripe as Stripe API
participant DB as Database
User->>Desktop: View Billing Overview
Desktop->>AuthServer: Get active organization & subscription
AuthServer->>DB: Query subscription by org ID
DB-->>AuthServer: Return subscription data (plan, status, cancelAt)
AuthServer-->>Desktop: Return subscription with plan
Desktop->>Desktop: Derive currentPlan from subscription
User->>Desktop: Click Upgrade Plan
Desktop->>AuthServer: Create checkout session
AuthServer->>Stripe: Create checkout session (organization metadata)
Stripe-->>AuthServer: Return checkout URL
AuthServer-->>Desktop: Return session URL
Desktop->>Stripe: Redirect to checkout
User->>Stripe: Complete payment
Stripe-->>AuthServer: Webhook: charge.succeeded
AuthServer->>DB: Update subscription status (active)
AuthServer->>Stripe: Retrieve subscription details
Stripe-->>AuthServer: Return subscription ID & period
User->>Desktop: View Billing (post-upgrade)
Desktop->>AuthServer: Get updated subscription
AuthServer->>DB: Query subscription
DB-->>AuthServer: Return updated subscription
AuthServer-->>Desktop: Return new plan (pro)
Desktop->>Desktop: Render CurrentPlanCard with active plan & cancel option
sequenceDiagram
participant Desktop as Desktop App
participant AuthServer as Auth Server
participant DB as Database
participant Stripe as Stripe API
rect rgba(200, 100, 100, 0.5)
Note over Desktop,DB: Add Member to Pro Plan Org
Desktop->>Desktop: Get current plan (pro)
Desktop->>Desktop: Show InviteMemberButton with plan prop
User->>Desktop: Click Invite Member
Desktop->>Desktop: Check plan == pro
Desktop->>Desktop: Show billing alert
User->>Desktop: Confirm invite
end
Desktop->>AuthServer: Invite member (with rate limit)
AuthServer->>AuthServer: Check inviter role permissions
AuthServer->>AuthServer: Enforce rate limit (10 per hour)
alt Rate limit OK
AuthServer->>DB: Insert invitation record
AuthServer->>Stripe: Update subscription quantity (members++)
Stripe-->>AuthServer: Confirm quantity updated
AuthServer-->>Desktop: Invitation sent
Desktop->>Desktop: Show toast success
else Rate limit exceeded
AuthServer-->>Desktop: Return error
Desktop->>Desktop: Show toast error
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~75 minutes Possibly related PRs
Poem
✨ Finishing touches
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 |
🚀 Preview Deployment🔗 Preview Links
Preview updates automatically with new commits |
Hide billing page from users without @superset.sh email until Stripe account is fully configured.
Uses PostHog feature flag
billing-enabledwhich is set to only allow users with @superset.sh emails.Changes:
Summary by CodeRabbit
Release Notes
New Features
Chores
✏️ Tip: You can customize this high-level summary in your review settings.