Skip to content

Conversation

@Ridhim-RR
Copy link

@Ridhim-RR Ridhim-RR commented Dec 5, 2025

What does this PR do?

Closes #4447

When a user's payment declines, the UI incorrectly shows the user as on the Free tier. Users on a paid/billing tier should continue to see their
billing tier while payment retries are in progress. The Free tier label should only be shown if the user is actually on the Free tier.

Fixes # (issue)
Updated the billing tier detection logic to treat payment statuses (past_due) as paid subscriptions for UI purposes:

  1. Updated isFreeTier logic to use hasPaidSubscription instead of checking subscription status directly:

If there is not an issue for this, please create one first. This is used to tracking purposes and also helps us understand why this PR exists

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • Chore (refactoring code, technical debt, workflow improvements)
  • Enhancement (small improvements)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How should this be tested?

  • Test A
  • Test B

Checklist

Required

  • Filled out the "How to test" section in this PR
  • Read Contributing Guide
  • Self-reviewed my own code
  • Commented on my code in hard-to-understand areas
  • Ran pnpm build
  • Ran pnpm fmt
  • Ran make fmt on /go directory
  • Checked for warnings, there are none
  • Removed all console.logs
  • Merged the latest changes from main onto my branch with git pull origin main
  • My changes don't cause any responsiveness issues

Appreciated

  • If a UI change was made: Added a screen recording or screenshots to this PR
  • Updated the Unkey Docs if changes were necessary

@changeset-bot
Copy link

changeset-bot bot commented Dec 5, 2025

⚠️ No Changeset found

Latest commit: 741bbf2

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@vercel
Copy link

vercel bot commented Dec 5, 2025

@Ridhim-RR is attempting to deploy a commit to the Unkey Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 5, 2025

📝 Walkthrough

Walkthrough

Changed billing-tier detection in the dashboard settings: introduced a hasPaidSubscription flag derived from presence of subscription and currentProductId and requiring subscription.status === "past_due". isFreeTier is now the negation of hasPaidSubscription. currentProduct assignment logic preserved.

Changes

Cohort / File(s) Summary
Billing status logic change
apps/dashboard/app/(app)/[workspaceSlug]/settings/billing/client.tsx
Added hasPaidSubscription computed from presence of subscription and currentProductId with subscription.status === "past_due". Replaced previous isFreeTier calculation with !hasPaidSubscription. Left allowUpdate and currentProduct selection structure unchanged.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10–15 minutes

  • Verify the subscription.status === "past_due" condition correctly covers the intended declined-payment display case and doesn't omit other expected paid statuses.
  • Confirm isFreeTier negation doesn't regress UI for active/other paid statuses.
  • Check currentProduct assignment logic remains correct in edge cases (missing product id, null subscription).

Pre-merge checks and finishing touches

❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Description check ❓ Inconclusive The PR description addresses the issue and explains the change, but the 'How should this be tested?' section lacks specific testing details. Replace placeholder 'Test A' and 'Test B' with actual test cases and reproduction steps that clearly demonstrate the fix for the billing tier display issue with declined payments.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main bug fix: correcting the billing tier display for declined payment statuses.
Linked Issues check ✅ Passed The PR successfully addresses the linked issue #4447 by implementing logic to treat declined payment statuses as paid subscriptions for UI purposes, preventing incorrect Free tier display.
Out of Scope Changes check ✅ Passed The changes are focused and scoped to the billing tier detection logic in the client component, directly addressing the issue without introducing unrelated modifications.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0740117 and 21a1c23.

📒 Files selected for processing (1)
  • apps/dashboard/app/(app)/[workspaceSlug]/settings/billing/client.tsx (1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: Flo4604
Repo: unkeyed/unkey PR: 4190
File: go/internal/services/keys/verifier.go:51-53
Timestamp: 2025-10-30T15:10:52.743Z
Learning: PR #4190 for unkeyed/unkey is focused solely on database schema and query changes for identity-based credits. It adds IdentityCredits and KeyCredits fields to structs and queries, but does not implement the priority enforcement logic in the usagelimiter. The logic implementation is intentionally deferred to a later PR in the stack.
📚 Learning: 2024-10-08T15:33:04.290Z
Learnt from: mcstepp
Repo: unkeyed/unkey PR: 2120
File: apps/dashboard/app/(app)/settings/billing/stripe/success/page.tsx:19-19
Timestamp: 2024-10-08T15:33:04.290Z
Learning: In the `StripeSuccess` function, TypeScript's type-checking of the `new_plan` parameter ensures that only "free", "pro", or undefined values are accepted, so additional runtime validation is not necessary.

Applied to files:

  • apps/dashboard/app/(app)/[workspaceSlug]/settings/billing/client.tsx
🔇 Additional comments (2)
apps/dashboard/app/(app)/[workspaceSlug]/settings/billing/client.tsx (2)

79-79: LGTM! Clean simplification of free tier detection.

The isFreeTier logic now correctly prevents showing the free tier alert during payment issues, which resolves the reported bug.


81-84: Verify that quota display and plan change policies align with business requirements during declined payment states.

The change now displays currentProduct for all paidStatuses including declined payments. This affects:

  • Line 99: Users see their paid tier quota even during past_due, unpaid, or incomplete states
  • Lines 108-115: Users can still access PlanSelectionModal to change plans during declined states

Before merging, confirm:

  1. The displayed quota on line 99 matches what the backend enforces when payments are declined
  2. Whether plan changes should be permitted (or restricted) during payment issues per your business policy

@Ridhim-RR Ridhim-RR changed the title fix(billing): billing-tier-display fix(billing): show correct tier for declined payment statuses Dec 5, 2025
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.

Fix billing tier display for declined payments

2 participants