-
Notifications
You must be signed in to change notification settings - Fork 11.5k
feat: (billing) monthly proration tracking #26531
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
sean-brydon
wants to merge
27
commits into
main
Choose a base branch
from
feat/billing-proration
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
+5,624
−61
Conversation
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
- 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
- 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
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.
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
Migration
Written for commit 1a58d08. Summary will update on new commits.