-
Notifications
You must be signed in to change notification settings - Fork 498
subscription renewal transactions #1005
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
subscription renewal transactions #1005
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. ✨ Finishing touches🧪 Generate unit tests (beta)
Tip 📝 Customizable high-level summaries are now available in beta!You can now customize how CodeRabbit generates the high-level summary in your pull requests — including its content, structure, tone, and formatting.
Example instruction:
Note: This feature is currently in beta for Pro-tier users, and pricing will be announced later. 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Greptile Overview
Greptile Summary
Adds tracking and display of subscription renewal transactions by creating a new SubscriptionInvoice database table and integrating it with the existing transactions system.
Key Changes:
- New
SubscriptionInvoicemodel stores Stripe invoice records withisSubscriptionCreationInvoiceflag to distinguish initial subscriptions from renewals handleStripeInvoicePaidfunction processesinvoice.payment_succeededwebhooks and stores invoice databuildSubscriptionRenewalTransactioncreates transaction entries for subscription renewals (money transfers only, no product grants)- Transaction listing API now queries subscription invoices and filters out creation invoices to show only renewals
- Cursor pagination extended to support the new subscription invoice data source
- Comprehensive test coverage verifies that subscription creation invoices are excluded from the renewal transaction list
Minor Changes:
- Fixed incorrect database port in docker compose configuration (8128 → 5432)
- UI improvements: replaced em dash with hyphen, migrated to
DateCellcomponent - Removed unused imports and fixed formatting inconsistencies
Confidence Score: 3/5
- This PR has one critical bug that will cause runtime errors when processing subscription renewals without USD pricing
- The implementation is well-structured with proper database migrations, comprehensive tests, and good separation of concerns. However, there's a critical bug in
buildSubscriptionRenewalTransactionat line 283 wherechargedAmount.USDis accessed without null checking, which will fail if a subscription doesn't have USD pricing. This violates the schema requirement thatnet_amount.USDmust be a string. - Pay close attention to
apps/backend/src/app/api/latest/internal/payments/transactions/transaction-builder.ts- the USD amount handling bug must be fixed before merging
Important Files Changed
File Analysis
| Filename | Score | Overview |
|---|---|---|
| apps/backend/src/lib/stripe.tsx | 4/5 | Implements handleStripeInvoicePaid to store invoice records and track subscription creation vs renewal |
| apps/backend/src/app/api/latest/integrations/stripe/webhooks/route.tsx | 5/5 | Adds call to handleStripeInvoicePaid on invoice.payment_succeeded events |
| apps/backend/src/app/api/latest/internal/payments/transactions/transaction-builder.ts | 3/5 | Adds buildSubscriptionRenewalTransaction builder with USD amount handling bug |
| apps/backend/src/app/api/latest/internal/payments/transactions/route.tsx | 4/5 | Integrates subscription invoices into transaction listing with cursor pagination support |
Sequence Diagram
sequenceDiagram
participant Stripe
participant Webhook as Stripe Webhook Handler
participant Handler as handleStripeInvoicePaid
participant DB as Database
participant API as Transactions API
participant UI as Dashboard UI
Note over Stripe,DB: Subscription Renewal Flow
Stripe->>Webhook: invoice.payment_succeeded event
Webhook->>Webhook: processStripeWebhookEvent()
Webhook->>Webhook: syncStripeSubscriptions()
Note over Webhook: Updates subscription status
Webhook->>Handler: handleStripeInvoicePaid(stripe, accountId, invoice)
Handler->>Handler: Extract subscription ID from invoice lines
Handler->>Handler: Check billing_reason for subscription_create
Handler->>DB: upsert SubscriptionInvoice
Note over DB: Stores invoice with<br/>isSubscriptionCreationInvoice flag
Note over API,UI: Transaction Display Flow
UI->>API: GET /api/latest/internal/payments/transactions
API->>DB: Query subscriptions
API->>DB: Query itemQuantityChanges
API->>DB: Query oneTimePurchases
API->>DB: Query subscriptionInvoices<br/>(WHERE isSubscriptionCreationInvoice = false)
DB-->>API: Return filtered invoices
API->>API: buildSubscriptionRenewalTransaction()<br/>for each invoice
API->>API: Merge & sort all transactions
API->>API: Apply cursor pagination
API-->>UI: Return transactions list
11 files reviewed, 1 comment
| adjusted_entry_index: null, | ||
| charged_amount: chargedAmount, | ||
| // todo: store net amount | ||
| net_amount: { USD: chargedAmount.USD }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: chargedAmount.USD could be undefined if the product price doesn't have a USD amount, causing a runtime error when assigned to net_amount.USD (which requires a string by schema)
| net_amount: { USD: chargedAmount.USD }, | |
| net_amount: { USD: chargedAmount.USD ?? "0" }, |
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/backend/src/app/api/latest/internal/payments/transactions/transaction-builder.ts
Line: 283:283
Comment:
**logic:** `chargedAmount.USD` could be undefined if the product price doesn't have a USD amount, causing a runtime error when assigned to `net_amount.USD` (which requires a string by schema)
```suggestion
net_amount: { USD: chargedAmount.USD ?? "0" },
```
How can I resolve this? If you propose a fix, please make it concise.…nt-subscription-renewal-transactions
apps/backend/src/app/api/latest/internal/payments/transactions/transaction-builder.ts
Show resolved
Hide resolved
<!-- Make sure you've read the CONTRIBUTING.md guidelines: https://github.com/stack-auth/stack-auth/blob/dev/CONTRIBUTING.md -->
No description provided.