Skip to content

fix(billing): correct URL construction and prevent double-redirecting#2034

Merged
jonathanlab merged 2 commits intomainfrom
posthog-code/fix-billing-link-navigation-issue
May 5, 2026
Merged

fix(billing): correct URL construction and prevent double-redirecting#2034
jonathanlab merged 2 commits intomainfrom
posthog-code/fix-billing-link-navigation-issue

Conversation

@jonathanlab
Copy link
Copy Markdown
Contributor

TL;DR

Fixes a critical billing navigation bug where the billing link was constructing malformed URLs with double schemes (e.g., https://us.posthog.com/project/219767/https://app.posthog.com/organization/billing), resulting in 404 errors. Introduces a dedicated getBillingUrl() function to ensure consistent, correct billing URL construction across the application.

What changed?

  • Added getBillingUrl() function in urls.ts that constructs the correct billing URL (/organization/billing/overview) with proper region handling
  • Fixed billing URL construction in PlanUsageSettings.tsx:
    • Replaced getPostHogUrl("/organization/billing") with getBillingUrl()
    • Fixed redirect URL logic to use the billing URL directly instead of attempting to construct a separate redirect URL that was causing double-scheme concatenation
  • Added comprehensive test coverage in urls.test.ts to prevent regression:
    • Tests for getPostHogUrl() behavior with different regions
    • Tests for getBillingUrl() returning correct URLs for US and EU regions
    • Explicit test case verifying the malformed double-scheme URL is no longer produced

How did you test this?

The changes include new unit tests in urls.test.ts that verify:

  • Correct URL construction for both US and EU regions
  • Proper handling of missing regions (returns null)
  • Prevention of malformed double-scheme URLs
  • No accidental inclusion of /project/ paths in billing URLs

Created with PostHog Code

Generated-By: PostHog Code
Task-Id: 156e6cbd-e2c4-4d62-bd3d-969dc2b57010
@jonathanlab jonathanlab enabled auto-merge (squash) May 5, 2026 14:06
@jonathanlab jonathanlab added the Create release This will trigger a new release label May 5, 2026
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 5, 2026

Prompt To Fix All With AI
Fix the following 3 code review issues. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 3
apps/code/src/renderer/utils/urls.test.ts:14-24
The region-specific test cases for both `getPostHogUrl` and `getBillingUrl` are repetitive and should be expressed as parameterised tests — the team's stated preference. Duplicate test bodies hide whether the assertion is actually exercising distinct behaviour or just paraphrasing the same check with different literals.

```suggestion
  it.each([
    ["us", "/foo", "https://us.posthog.com/foo"],
    ["us", "foo", "https://us.posthog.com/foo"],
    ["eu", "/foo", "https://eu.posthog.com/foo"],
  ])("joins base and path for %s region (path=%s)", (region, path, expected) => {
    expect(getPostHogUrl(path, region as "us" | "eu")).toBe(expected);
  });
```

### Issue 2 of 3
apps/code/src/renderer/utils/urls.test.ts:28-38
Same parameterisation opportunity for the `getBillingUrl` region cases — the two "points at" tests differ only in region and expected host, making `it.each` the right tool.

```suggestion
  it.each([
    ["us", "https://us.posthog.com/organization/billing/overview"],
    ["eu", "https://eu.posthog.com/organization/billing/overview"],
  ])("points at /organization/billing/overview on %s", (region, expected) => {
    expect(getBillingUrl(region as "us" | "eu")).toBe(expected);
  });
```

### Issue 3 of 3
apps/code/src/renderer/features/settings/components/sections/PlanUsageSettings.tsx:71
**`redirectUrl` value is silently discarded**

The old code passed `redirectUrl` to `getPostHogUrl()` as the path — that was broken when the backend returned a full URL. The new code fixes the double-scheme issue, but now completely ignores the backend-supplied URL: `redirectUrl` only controls whether the callout is shown; its actual value is thrown away. If the backend ever sends a redirect to a specific checkout or payment-setup page (rather than the generic billing overview), users will silently land on the wrong page.

```suggestion
  const redirectFullUrl = redirectUrl ? billingUrl : null;
```

Reviews (1): Last reviewed commit: "fix: correct billing URL construction an..." | Re-trigger Greptile

Comment thread apps/code/src/renderer/utils/urls.test.ts Outdated
Comment thread apps/code/src/renderer/utils/urls.test.ts Outdated
@jonathanlab jonathanlab disabled auto-merge May 5, 2026 14:12
Address Greptile feedback on PR #2034:
- getPostHogUrl now passes absolute URLs through unchanged, so a
  backend-supplied redirect_url is no longer flattened into the generic
  billing overview when it points at a specific checkout/payment page.
- PlanUsageSettings runs redirectUrl through getPostHogUrl again and
  falls back to the static billing URL only when the value can't be
  resolved.
- Tests for region variants are parameterized with it.each, plus new
  coverage for absolute-URL passthrough.

Generated-By: PostHog Code
Task-Id: 156e6cbd-e2c4-4d62-bd3d-969dc2b57010
@jonathanlab jonathanlab enabled auto-merge (squash) May 5, 2026 14:16
@jonathanlab jonathanlab merged commit 34d8e03 into main May 5, 2026
15 checks passed
@jonathanlab jonathanlab deleted the posthog-code/fix-billing-link-navigation-issue branch May 5, 2026 14:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Create release This will trigger a new release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants