Skip to content

Conversation

@a-lider
Copy link
Contributor

@a-lider a-lider commented Oct 3, 2025

Problem

This PR adds a minimal version for plan switch under a feature flag. It allows you to upgrade or downgrade the platform addon.
Confirmation modal and prorated amount calculation will be in a follow-up PR.
This version is planned to be released internally, only for testing.

Changes

How did you test this code?

Locally

  • Make sure switch-subscription-plan feature flag (release toggle) is enabled
  • Open the billing page and add any of the platform addons
  • Click Downgrade on the lower-tier addon or Upgrade on the higher-tier addon

@github-actions
Copy link
Contributor

github-actions bot commented Oct 3, 2025

Size Change: +1.06 kB (+0.03%)

Total Size: 3.05 MB

Filename Size Change
frontend/dist/toolbar.js 3.05 MB +1.06 kB (+0.03%)

compressed-size-action

@posthog-bot
Copy link
Contributor

📸 UI snapshots have been updated

1 snapshot changes in total. 0 added, 1 modified, 0 deleted:

  • chromium: 0 added, 1 modified, 0 deleted (diff for shard 15)
  • webkit: 0 added, 0 modified, 0 deleted

Triggered by this commit.

👉 Review this PR's diff of snapshots.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks like flaky test, unrelated change

@a-lider a-lider marked this pull request as ready for review October 6, 2025 14:20
@a-lider a-lider requested a review from a team October 6, 2025 14:20
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.

6 files reviewed, 3 comments

Edit Code Review Agent Settings | Greptile

Comment on lines +225 to +229
from_product_key: String(currentPlatformAddon?.type),
from_plan_key: String(currentPlatformAddon?.plans[0].plan_key),
to_product_key: addon.type,
to_plan_key: String(upgradePlan?.plan_key),
})
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: Potential runtime error if currentPlatformAddon is undefined or plans array is empty. Add null safety checks.

Prompt To Fix With AI
This is a comment left during a code review.
Path: frontend/src/scenes/billing/BillingProductAddonActions.tsx
Line: 225:229

Comment:
**logic:** Potential runtime error if currentPlatformAddon is undefined or plans array is empty. Add null safety checks.

How can I resolve this? If you propose a fix, please make it concise.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added check for currentPlatformAddon

Comment on lines +259 to +263
from_product_key: String(currentPlatformAddon?.type),
from_plan_key: String(currentPlatformAddon?.plans[0].plan_key),
to_product_key: addon.type,
to_plan_key: String(upgradePlan?.plan_key),
})
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: Same issue as downgrade - needs null safety for currentPlatformAddon and plans[0]

Prompt To Fix With AI
This is a comment left during a code review.
Path: frontend/src/scenes/billing/BillingProductAddonActions.tsx
Line: 259:263

Comment:
**logic:** Same issue as downgrade - needs null safety for currentPlatformAddon and plans[0]

How can I resolve this? If you propose a fix, please make it concise.

Comment on lines +272 to +277
@action(methods=["POST"], detail=False, url_path="subscription/switch-plan")
def subscription_switch_plan(self, request: Request, *args: Any, **kwargs: Any) -> HttpResponse:
organization = self._get_org_required()
billing_manager = self.get_billing_manager()
res = billing_manager.switch_plan(organization, request.data)
return Response(res, status=status.HTTP_200_OK)
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: Missing error handling for the switch_plan operation. Other billing endpoints in this file (like deactivate, get_invoices) have try-catch blocks to handle billing service errors gracefully and return appropriate error responses.

Prompt To Fix With AI
This is a comment left during a code review.
Path: ee/api/billing.py
Line: 272:277

Comment:
**logic:** Missing error handling for the switch_plan operation. Other billing endpoints in this file (like deactivate, get_invoices) have try-catch blocks to handle billing service errors gracefully and return appropriate error responses.

How can I resolve this? If you propose a fix, please make it concise.

Copy link
Contributor Author

@a-lider a-lider Oct 6, 2025

Choose a reason for hiding this comment

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

If the billing request fails, this will return a 500 error, and the user sees a toast "There was an error switching your plan. Please try again or contact support." This is handled in billingLogic.tsx
So I don’t think we need to expose detailed errors from billing (like validation errors).

Copy link
Contributor

@zlwaterfield zlwaterfield left a comment

Choose a reason for hiding this comment

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

Looks good, great work iterating, let's get this and the modal one out so we can test it all together.

try {
await api.create('api/billing/subscription/switch-plan', data)

const productDisplayName = data.to_product_key[0].toUpperCase() + data.to_product_key.slice(1)
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: I think we have a util function for this somewhere

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed


return values.billing as BillingType
} catch (error: any) {
console.error(error)
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove console log and instead capture the error

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, thanks, forgot to remove this

@posthog-bot
Copy link
Contributor

📸 UI snapshots have been updated

1 snapshot changes in total. 0 added, 1 modified, 0 deleted:

  • chromium: 0 added, 1 modified, 0 deleted (diff for shard 15)
  • webkit: 0 added, 0 modified, 0 deleted

Triggered by this commit.

👉 Review this PR's diff of snapshots.

@a-lider a-lider force-pushed the alex/feat/plan-switch/without-confirmation branch from d2aa4c2 to b91a944 Compare October 9, 2025 13:02
@a-lider a-lider enabled auto-merge (squash) October 9, 2025 13:08
@a-lider a-lider merged commit d0f676f into master Oct 9, 2025
184 of 185 checks passed
@a-lider a-lider deleted the alex/feat/plan-switch/without-confirmation branch October 9, 2025 13:24
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.

4 participants