Skip to content

feat(billing): add comprehensive usage-based billing system#625

Merged
waleedlatif1 merged 13 commits intostagingfrom
feat/usage-based-billing-clean
Jul 10, 2025
Merged

feat(billing): add comprehensive usage-based billing system#625
waleedlatif1 merged 13 commits intostagingfrom
feat/usage-based-billing-clean

Conversation

@waleedlatif1
Copy link
Collaborator

@waleedlatif1 waleedlatif1 commented Jul 7, 2025

  • Complete billing infrastructure with subscription management
  • Usage tracking and limits for organizations
  • Team management with role-based permissions
  • CRON jobs for automated billing and cleanup
  • Stripe integration for payments and invoicing
  • Email notifications for billing events
  • Organization-based workspace management
  • API endpoints for billing operations

Description

Added usage based billing, where users can adjust their own limits and the billing is handled automatically at the end of the billing period via CRON.

Type of change

  • New feature (non-breaking change which adds functionality)

How Has This Been Tested?

Tested purchasing a team subscription manually, and inviting people to the team and adjusting their limits.

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added tests that prove my fix is effective or that my feature works
  • All tests pass locally and in CI (bun run test)
  • My changes generate no new warnings
  • Any dependent changes have been merged and published in downstream modules
  • I have updated version numbers as needed (if needed)
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

Security Considerations:

  • My changes do not introduce any new security vulnerabilities
  • I have considered the security implications of my changes

@vercel
Copy link

vercel bot commented Jul 7, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
sim ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 10, 2025 5:40am
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
docs ⬜️ Skipped (Inspect) Jul 10, 2025 5:40am

@delve-auditor
Copy link

delve-auditor bot commented Jul 7, 2025

No security or compliance issues detected. Reviewed everything up to 637ba6c.

Security Overview
  • 🔎 Scanned files: 105 changed file(s)
Detected Code Changes

The diff is too large to display a summary of code changes.

Reply to this PR with @delve-auditor followed by a description of what change you want and we'll auto-submit a change to this PR to implement it.

- Complete billing infrastructure with subscription management
- Usage tracking and limits for organizations
- Team management with role-based permissions
- CRON jobs for automated billing and cleanup
- Stripe integration for payments and invoicing
- Email notifications for billing events
- Organization-based workspace management
- API endpoints for billing operations
@waleedlatif1 waleedlatif1 marked this pull request as ready for review July 9, 2025 21:50
@waleedlatif1 waleedlatif1 reopened this Jul 9, 2025
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

Major overhaul implementing a comprehensive usage-based billing system with Stripe integration, team management, and automated billing processes.

  • Consolidated billing architecture in lib/billing/ with usage tracking, subscription management, and automated CRON jobs for period-based billing
  • Introduced organization-level management with stores/organization/store.ts providing workspace access control and member limit management
  • Added team-focused billing UI components including TeamSeatsOverview and UsageLimitEditor for granular control over member usage limits
  • Implemented secure Stripe webhooks in api/billing/webhooks/stripe/route.ts for handling payment events with proper signature verification
  • Removed legacy waitlist system including email templates and API routes in favor of direct subscription management

100 files reviewed, 57 comments
Edit PR Review Bot Settings | Greptile

@icecrasher321
Copy link
Collaborator

@waleedlatif1 We don't have a way to cancel subscriptions?

  1. We need some button that sets this field to cancelAtPeriodEnd: boolean('cancel_at_period_end') in subscriptions to true -- and I think the stripe client somewhere should handle it to actually cancel the subscription. I couldn't find this logic.

  2. For upgrades / downgrades -- reading best practices:

Upgrades: Usually immediate with proration (charge difference immediately)
Downgrades: Can be immediate OR scheduled for end of period [i think end of period is good -- netflix does this. But i'm not sure how it works with our table system. We'd need a subscription row that goes into effect once the other one ends or does Stripe have something? Or if immediate with proration is easier, we can do that and keep it the same as downgrades basically.

@vercel vercel bot temporarily deployed to Preview – docs July 10, 2025 05:37 Inactive
@waleedlatif1 waleedlatif1 merged commit e5080fe into staging Jul 10, 2025
6 checks passed
@waleedlatif1 waleedlatif1 deleted the feat/usage-based-billing-clean branch July 10, 2025 22:24
arenadeveloper02 pushed a commit to arenadeveloper02/p2-sim that referenced this pull request Sep 19, 2025
…oai#625)

* feat(billing): add comprehensive usage-based billing system

- Complete billing infrastructure with subscription management
- Usage tracking and limits for organizations
- Team management with role-based permissions
- CRON jobs for automated billing and cleanup
- Stripe integration for payments and invoicing
- Email notifications for billing events
- Organization-based workspace management
- API endpoints for billing operations

* fix tests, standardize datetime logic

* add lazy init for stripe client, similar to s3

* cleanup

* ack PR comments

* fixed build

* convert everything to UTC

* add delete subscription functionality using better auth

* fix lint

* fix linter error

* remove invoice emails since it is natively managed via stripe

* fix build

---------

Co-authored-by: Vikhyath Mondreti <vikhyathmondreti@Vikhyaths-Air.attlocal.net>
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