improvement(admin-routes): cleanup code that could accidentally desync stripe and DB#2363
improvement(admin-routes): cleanup code that could accidentally desync stripe and DB#2363icecrasher321 merged 2 commits intostagingfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
Greptile OverviewGreptile SummaryThis PR improves billing system correctness by removing admin routes that could desync Stripe and the database. The key changes:
Confidence Score: 5/5
Important Files ChangedFile Analysis
Sequence DiagramsequenceDiagram
participant Admin as Admin API
participant DB as Database
participant Stripe as Stripe API
participant Webhook as Stripe Webhook
Note over Admin,Webhook: Before: Direct DB updates could desync
Admin->>DB: PATCH seats/subscription (old)
Note right of DB: ⚠️ Stripe not updated
Note over Admin,Webhook: After: Stripe-first approach
Admin->>Stripe: DELETE subscription (cancel)
Stripe-->>Webhook: subscription.deleted event
Webhook->>DB: Update status
Webhook->>DB: Reset usage
Webhook->>Stripe: Restore Pro subscriptions
Webhook->>DB: Delete organization
Webhook->>DB: Sync usage limits
|
Summary
Current billing system is event based and designed entirely around stripe webhook events triggering db updates. When done directly via an Admin route -- this can be complicated since edge case logic for thigns like seat updates, plan upgrades/downgrades involve multiple steps of bookkeeping on our side and on stripe. It's also not good practice to autocharge customers without notifying them.
This PR makes sure correctness and simplifies to only have delete subscription ops. Complex ops should otherwise be executed using Stripe CLI.
Type of Change
Testing
Tested manually.
Checklist