Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@BilalG1
Copy link
Contributor

@BilalG1 BilalG1 commented Nov 7, 2025

No description provided.

@vercel
Copy link

vercel bot commented Nov 7, 2025

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

Project Deployment Preview Comments Updated (UTC)
stack-backend Ready Ready Preview Comment Nov 18, 2025 7:47pm
stack-dashboard Ready Ready Preview Comment Nov 18, 2025 7:47pm
stack-demo Ready Ready Preview Comment Nov 18, 2025 7:47pm
stack-docs Ready Ready Preview Comment Nov 18, 2025 7:47pm

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 7, 2025

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Note

Other AI code review bot(s) detected

CodeRabbit 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)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch payment-subscription-renewal-transactions

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.

  • Provide your own instructions using the high_level_summary_instructions setting.
  • Format the summary however you like (bullet lists, tables, multi-section layouts, contributor stats, etc.).
  • Use high_level_summary_in_walkthrough to move the summary from the description to the walkthrough section.

Example instruction:

"Divide the high-level summary into five sections:

  1. 📝 Description — Summarize the main change in 50–60 words, explaining what was done.
  2. 📓 References — List relevant issues, discussions, documentation, or related PRs.
  3. 📦 Dependencies & Requirements — Mention any new/updated dependencies, environment variable changes, or configuration updates.
  4. 📊 Contributor Summary — Include a Markdown table showing contributions:
    | Contributor | Lines Added | Lines Removed | Files Changed |
  5. ✔️ Additional Notes — Add any extra reviewer context.
    Keep each section concise (under 200 words) and use bullet or numbered lists for clarity."

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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.

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 SubscriptionInvoice model stores Stripe invoice records with isSubscriptionCreationInvoice flag to distinguish initial subscriptions from renewals
  • handleStripeInvoicePaid function processes invoice.payment_succeeded webhooks and stores invoice data
  • buildSubscriptionRenewalTransaction creates 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 DateCell component
  • 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 buildSubscriptionRenewalTransaction at line 283 where chargedAmount.USD is accessed without null checking, which will fail if a subscription doesn't have USD pricing. This violates the schema requirement that net_amount.USD must 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
Loading

11 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

adjusted_entry_index: null,
charged_amount: chargedAmount,
// todo: store net amount
net_amount: { USD: chargedAmount.USD },
Copy link
Contributor

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)

Suggested change
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.

@BilalG1 BilalG1 requested a review from N2D4 November 12, 2025 17:05
@BilalG1 BilalG1 merged commit 19dfcff into payment-transactions Nov 18, 2025
14 of 18 checks passed
@BilalG1 BilalG1 deleted the payment-subscription-renewal-transactions branch November 18, 2025 19:40
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.

3 participants