Skip to content

fix(frontend): cache Stripe portal URL - #2892

Open
WcaleNieWolny wants to merge 6 commits into
mainfrom
wolny/cache-stripe-portal-url
Open

fix(frontend): cache Stripe portal URL#2892
WcaleNieWolny wants to merge 6 commits into
mainfrom
wolny/cache-stripe-portal-url

Conversation

@WcaleNieWolny

@WcaleNieWolny WcaleNieWolny commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Summary

  • open the Stripe billing dialog immediately instead of waiting on a session lookup
  • reuse successful organization-scoped portal URLs for up to three minutes
  • preserve the existing error behavior and cover timing, expiry, rejection, and organization isolation

Test plan

  • bun lint
  • bun typecheck
  • bun test:unit
  • bun run build

View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

Review in cubic

Summary by CodeRabbit

  • Bug Fixes

    • Improved Stripe billing portal access by allowing requests without an active session.
    • Preserved the existing error message when the billing portal cannot be opened.
    • Improved loading behavior while retrieving portal access links.
    • Refreshes links when the callback destination changes.
  • Performance

    • Reuses recently retrieved billing portal links for up to three minutes.
    • Refreshes expired links and keeps links separate for each organization.

@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The Stripe portal flow removes the session check, caches successful URLs per organization for three minutes, handles failures as unavailable URLs, and awaits the shared URL before opening the portal. Tests cover pending requests, failures, expiration, callback changes, and organization isolation.

Changes

Stripe portal cache

Layer / File(s) Summary
Portal URL caching and dialog flow
src/services/stripe.ts
openPortal caches successful Stripe portal URLs per organization for three minutes, reuses matching callback URLs, converts failures to empty results, and awaits the shared URL before opening the portal.
Portal cache test coverage
tests/stripe-portal-cache.unit.test.ts
Tests cover pending dialogs, rejected requests, cache expiration, callback URL changes, refreshed URLs, and organization-specific cache isolation.

Estimated code review effort: 3 (Moderate) | ~15–30 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description includes a summary and test plan but omits the required Screenshots and Checklist sections. Add the Screenshots and Checklist sections, and mark the applicable checklist items.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main frontend change: caching Stripe portal URLs.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/services/stripe.ts`:
- Around line 40-58: Update portalUrlCache and the cache access in openPortal so
entries are stored independently by organization ID rather than replacing a
single shared entry. Preserve the existing three-minute TTL and URL-fetch
behavior, and ensure the org-a, org-b, org-a sequence reuses org-a’s cached URL
with only two API calls; add coverage for this sequence.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: f8171303-67b7-4bb0-827d-2a7345fc3bed

📥 Commits

Reviewing files that changed from the base of the PR and between 60a641e and c8de37b.

📒 Files selected for processing (2)
  • src/services/stripe.ts
  • tests/stripe-portal-cache.unit.test.ts
🔗 Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

  • Cap-go/capacitor-updater (manual)

Comment thread src/services/stripe.ts
@codspeed-hq

codspeed-hq Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 43 untouched benchmarks
⏩ 2 skipped benchmarks1


Comparing wolny/cache-stripe-portal-url (0c98a7f) with main (60a641e)2

Open in CodSpeed

Footnotes

  1. 2 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

  2. No successful run was found on main (8b32a45) during the generation of this report, so 60a641e was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

All reported issues were addressed across 2 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread src/services/stripe.ts Outdated

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

All reported issues were addressed across 2 files (changes from recent commits).

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread src/services/stripe.ts Outdated
Comment thread src/services/stripe.ts Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/services/stripe.ts (1)

78-83: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Preserve transient user activation before awaiting portalUrl.

When portalUrl is pending, openBlank(url) runs after the confirm click task. Browsers can block window.open, so the portal does not open.

On web, open a blank tab synchronously and navigate it after portalUrl resolves. Close the tab and show the existing error toast when no URL is available. Add browser coverage for this pending-request path.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/services/stripe.ts` around lines 78 - 83, Update the confirm handler
around portalUrl to open a blank browser tab synchronously before awaiting the
pending URL, then navigate that tab once the URL resolves. If no URL is
returned, close the blank tab and retain the existing “Cannot open your portal”
toast; add browser coverage for the pending-request flow.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@src/services/stripe.ts`:
- Around line 78-83: Update the confirm handler around portalUrl to open a blank
browser tab synchronously before awaiting the pending URL, then navigate that
tab once the URL resolves. If no URL is returned, close the blank tab and retain
the existing “Cannot open your portal” toast; add browser coverage for the
pending-request flow.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: d855be2e-4333-438d-a927-2608dfc85d48

📥 Commits

Reviewing files that changed from the base of the PR and between c8de37b and b874897.

📒 Files selected for processing (2)
  • src/services/stripe.ts
  • tests/stripe-portal-cache.unit.test.ts
🔗 Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

  • Cap-go/capacitor-updater (manual)

@sonarqubecloud

sonarqubecloud Bot commented Aug 6, 2026

Copy link
Copy Markdown

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.

1 participant