Skip to content

Conversation

@sean-brydon
Copy link
Member

@sean-brydon sean-brydon commented Jan 7, 2026

Summary by cubic

Introduces monthly proration for annual plans: we track seat changes per month and bill a single Stripe proration on the 1st of the next month. Feature is behind a flag for a safe rollout. Adds an admin billing stats page to monitor and manually trigger prorations.

  • New Features

    • Track seat additions/removals per team with a month key.
    • Determine plan eligibility and trial status to decide when to prorate.
    • Calculate prorated amounts and create/finalize Stripe invoices; update status via payment succeeded/failed webhooks.
    • Persist billing period, price per seat, and paid seats (high‑water mark); reset paid seats on renewal.
    • Vercel cron endpoint at /api/cron/monthly-proration scheduled for 00:05 UTC on the 1st.
    • Skip immediate quantity updates for annual plans; log member removals to feed proration.
    • Admin billing stats page at /settings/admin/billing-stats with stats and manual triggers.
    • Repositories and tests covering end-to-end proration flow.
  • Migration

    • Run the Prisma migration to add proration tables and fields, including paidSeats high‑water mark.
    • Configure the cron route and Stripe webhooks for invoice events.
    • Enable the monthly-proration feature flag after validation.

Written for commit 1a58d08. Summary will update on new commits.

- Add SeatChangeLog model to track seat additions/removals
- Add MonthlyProration model to track proration charges
- Add SeatChangeType and ProrationStatus enums
- Update TeamBilling and OrganizationBilling with billingPeriod and pricePerSeat
- Add relations to Team model for proration tracking
- Track seat additions and removals with month key
- Calculate monthly changes and net seat increase
- Support both team and organization billing
- Include comprehensive unit tests (12 passing)
- Determine billing period (monthly/annual) and trial status
- Validate proration eligibility for teams/orgs
- Support updating billing period information
- Include comprehensive unit tests (19 passing)
- Skip immediate Stripe updates for annual plans in TeamBillingService
- Log seat additions on team invitation acceptance
- Log seat removals when members are removed
- Only track for annual plans not in trial
- add service to process monthly prorations for annual plans
- calculate prorated charges based on remaining subscription days
- create stripe invoice items for proration charges
- handle payment success and failure callbacks
- support retry logic for failed prorations
- includes comprehensive unit tests (10 tests passing)
- add invoice.payment_succeeded handler to mark prorations as charged
- add invoice.payment_failed handler to track failed payments
- update webhook router to register new event handlers
- handlers check for monthly_proration metadata before processing
- add trigger.dev task for processing monthly prorations
- add manual trigger task for testing and specific team processing
- update trigger.config.ts to include billing trigger directory
- add vercel cron endpoint at /api/cron/monthly-proration
- configure cron to run at 00:05 UTC on 1st of each month
- add README documenting task usage and deployment
trigger.dev v4 doesn't support cron schedules in task definitions.
vercel cron endpoint is sufficient for monthly processing.
- add integration tests for MonthlyProrationService end-to-end flows
- add unit tests for invoice payment webhook handlers
- tests cover proration creation, payment success/failure callbacks
- tests cover webhook handling for proration line items
…ration

- add 'monthly-proration' feature flag to AppFlags config
- update BillingPeriodService to check feature flag before applying proration
- create populate-billing-periods migration script for existing subscriptions
- add comprehensive MIGRATION.md with rollout guide and monitoring queries
- feature is disabled by default for gradual rollout
@github-actions github-actions bot added the ❗️ migrations contains migration files label Jan 7, 2026
@vercel
Copy link

vercel bot commented Jan 7, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

4 Skipped Deployments
Project Deployment Review Updated (UTC)
api-v2 Ignored Ignored Preview Jan 9, 2026 1:23am
cal Ignored Ignored Jan 9, 2026 1:23am
cal-companion Ignored Ignored Preview Jan 9, 2026 1:23am
cal-eu Ignored Ignored Jan 9, 2026 1:23am

- Replace all await import() with static imports
- Create and finalize Stripe invoices immediately instead of waiting for next billing cycle
- Add feature flag to migration (disabled by default)
- Remove MIGRATION.md file
…ggers

- add /settings/admin/billing-stats page with RSC queries
- display proration overview, seat changes, and team billing stats
- add server actions to trigger proration early for testing
- include links to stripe invoices, customers, and subscriptions
- add admin-protected mutations with security checks
- improve integration test cleanup to remove all database records
- verify removals don't create credits or negative charges
- net change capped at 0 when removals exceed additions
- subscription quantity remains unchanged until renewal
- add comment explaining annual plan seat removal behavior
backfills billing period, price per seat, and paid seats from stripe when missing.
renamed getBillingPeriodInfo to getOrCreateBillingPeriodInfo to make side effects clear.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

❗️ migrations contains migration files size/XXL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants