Skip to content

fix payment data integrity#1137

Merged
BilalG1 merged 1 commit intodevfrom
fix-payment-data-integrity
Jan 28, 2026
Merged

fix payment data integrity#1137
BilalG1 merged 1 commit intodevfrom
fix-payment-data-integrity

Conversation

@BilalG1
Copy link
Contributor

@BilalG1 BilalG1 commented Jan 28, 2026

Summary by CodeRabbit

  • Bug Fixes

    • Fixed an issue where include-by-default products were not appearing in subscription results when other products in the same product line had only inactive subscriptions.
  • Tests

    • Added test coverage for include-by-default product behavior in subscription scenarios with inactive subscriptions.

✏️ Tip: You can customize this high-level summary in your review settings.

@vercel
Copy link

vercel bot commented Jan 28, 2026

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

Project Deployment Review Updated (UTC)
stack-backend Ready Ready Preview, Comment Jan 28, 2026 0:27am
stack-dashboard Ready Ready Preview, Comment Jan 28, 2026 0:27am
stack-demo Ready Ready Preview, Comment Jan 28, 2026 0:27am
stack-docs Ready Ready Preview, Comment Jan 28, 2026 0:27am

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 28, 2026

📝 Walkthrough

Walkthrough

The changes modify getSubscriptions to properly include include-by-default products when product lines only contain inactive subscriptions. A test case is added to verify this behavior, while the implementation tightens the condition for tracking which product lines have active database subscriptions.

Changes

Cohort / File(s) Change Summary
Test Coverage
apps/backend/src/lib/payments.test.tsx
Adds new test case verifying that include-by-default products (freeG1) appear in subscriptions even when their product line only has inactive/canceled subscriptions (paidG1). Mirrors existing ungrouped include-by-default product test.
Subscription Logic
apps/backend/src/lib/payments.tsx
Refactors getSubscriptions to construct subscription objects locally before pushing and tightens product line tracking by only adding productLineId when subscription is both defined and active.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • N2D4

Poem

🐰 A subscription fix hops into view,
Include-by-default products shine anew,
When lines sleep softly, products stay true,
Active checks keep logic tight and new! 🌿

🚥 Pre-merge checks | ❌ 3
❌ Failed checks (2 warnings, 1 inconclusive)
Check name Status Explanation Resolution
Description check ⚠️ Warning The pull request description contains only the repository template placeholder comment with no actual descriptive content about the changes, objectives, or rationale. Add a detailed description explaining what was fixed, why the changes were necessary, and how they address the payment data integrity issue. Include context about the subscription behavior change.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'fix payment data integrity' is vague and generic, using non-descriptive language that doesn't clarify the specific payment issue being addressed. Provide a more specific title that describes the actual fix, such as 'Fix include-by-default product visibility in getSubscriptions when only inactive subscriptions exist' or similar.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

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.

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Jan 28, 2026

Greptile Overview

Greptile Summary

This PR fixes a data integrity bug in the subscription system where customers with only canceled/inactive subscriptions in a product line were not receiving their include-by-default products.

Key Changes:

  • Modified getSubscriptions() to check isActiveSubscription() before tracking product lines with subscriptions
  • Ensured that product lines with only inactive subscriptions are treated as having no active subscriptions, allowing the default product to be included
  • Added comprehensive test coverage for the scenario where only inactive subscriptions exist in a product line

Impact:
The fix ensures customers always have access to their free tier or default products when they cancel paid subscriptions, preventing loss of base functionality.

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The fix is surgical, well-tested, and addresses a clear data integrity bug. The change adds a single condition check that correctly filters out inactive subscriptions when determining product line availability. The new test case provides comprehensive coverage of the edge case being fixed.
  • No files require special attention

Important Files Changed

Filename Overview
apps/backend/src/lib/payments.tsx Fixed data integrity bug by checking subscription status before tracking product lines
apps/backend/src/lib/payments.test.tsx Added test coverage for include-by-default products with inactive subscriptions

Sequence Diagram

sequenceDiagram
    participant Client
    participant getSubscriptions
    participant Database
    participant ProductLineLogic

    Client->>getSubscriptions: Request subscriptions for customer
    getSubscriptions->>Database: Query all subscriptions
    Database-->>getSubscriptions: Return subscription records
    
    getSubscriptions->>getSubscriptions: Loop through subscriptions
    getSubscriptions->>getSubscriptions: Create subscription object
    getSubscriptions->>getSubscriptions: Check if isActiveSubscription()
    
    alt Subscription is active AND has productLineId
        getSubscriptions->>ProductLineLogic: Add to productLinesWithDbSubscriptions
    else Subscription is canceled/inactive
        getSubscriptions->>ProductLineLogic: Skip - don't add to set
    end
    
    getSubscriptions->>ProductLineLogic: Check each product line
    
    loop For each product line
        alt No active subscriptions in line
            ProductLineLogic->>ProductLineLogic: Find include-by-default product
            ProductLineLogic->>getSubscriptions: Add default subscription
        else Has active subscription
            ProductLineLogic->>ProductLineLogic: Skip - customer already has active product
        end
    end
    
    getSubscriptions-->>Client: Return all subscriptions (active + defaults)
Loading

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.

No files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@BilalG1 BilalG1 requested a review from N2D4 January 28, 2026 00:48
@BilalG1 BilalG1 assigned N2D4 and unassigned BilalG1 Jan 28, 2026
@github-actions github-actions bot assigned BilalG1 and unassigned N2D4 Jan 28, 2026
@BilalG1 BilalG1 merged commit d3fb974 into dev Jan 28, 2026
33 checks passed
@BilalG1 BilalG1 deleted the fix-payment-data-integrity branch January 28, 2026 17:01
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