fix(Billing): Free trial buttons stop working after toggling yearly/monthly#7335
fix(Billing): Free trial buttons stop working after toggling yearly/monthly#7335
Conversation
…onthly Chargebee's DOM-scan registration (`registerAgain`) only ran on the first `initChargebee` call, so the `PaymentButton` instances remounted by the yearly/monthly toggle picked up no click handler and silently did nothing. Call `registerAgain` on every `initChargebee` entry (one-time init stays guarded) and re-run the effect when the toggle changes. beep boop
There was a problem hiding this comment.
Code review is billed via overage credits. To resume reviews, an organization admin can raise the monthly limit at claude.ai/admin-settings/claude-code.
Once credits are available, reopen this pull request to trigger a review.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Docker builds report
|
Playwright Test Results (oss - depot-ubuntu-latest-16)Details
Playwright Test Results (oss - depot-ubuntu-latest-arm-16)Details
Playwright Test Results (private-cloud - depot-ubuntu-latest-16)Details
Playwright Test Results (private-cloud - depot-ubuntu-latest-arm-16)Details
Playwright Test Results (oss - depot-ubuntu-latest-16)Details
Playwright Test Results (oss - depot-ubuntu-latest-arm-16)Details
Playwright Test Results (private-cloud - depot-ubuntu-latest-arm-16)Details
Playwright Test Results (private-cloud - depot-ubuntu-latest-16)Details
Playwright Test Results (oss - depot-ubuntu-latest-16)Details
Playwright Test Results (oss - depot-ubuntu-latest-arm-16)Details
Playwright Test Results (private-cloud - depot-ubuntu-latest-arm-16)Details
Playwright Test Results (private-cloud - depot-ubuntu-latest-16)Details
Playwright Test Results (oss - depot-ubuntu-latest-16)Details
Playwright Test Results (oss - depot-ubuntu-latest-arm-16)Details
Playwright Test Results (private-cloud - depot-ubuntu-latest-arm-16)Details
Playwright Test Results (private-cloud - depot-ubuntu-latest-16)Details
Playwright Test Results (oss - depot-ubuntu-latest-16)Details
Playwright Test Results (oss - depot-ubuntu-latest-arm-16)Details
Playwright Test Results (private-cloud - depot-ubuntu-latest-16)Details
Playwright Test Results (private-cloud - depot-ubuntu-latest-arm-16)Details
|
Visual Regression16 screenshots compared. See report for details. |
Billing only exists on SaaS (Chargebee, trial buttons, paid plan toggles), so the @enterprise tag was a misnomer: private-cloud builds don't ship payments and the runtime flag-guard skipped the test there anyway. Introduce a @SaaS marker and wire it into the staging/production E2E runs alongside @oss and @enterprise, so the same grep makes intent explicit and leaves private-cloud runs free of payments-only tests. beep boop
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #7335 +/- ##
=======================================
Coverage 98.42% 98.42%
=======================================
Files 1393 1393
Lines 52304 52304
=======================================
Hits 51481 51481
Misses 823 823 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
PaymentButton only hits the Chargebee DOM-scan branch (where the bug lives) when the organisation has no active subscription. e2e_user's org is seeded on Enterprise with a live subscription_id for the rest of the suite, so billing tests can't reach the buggy code path on it. Add e2e_billing_user on its own organisation, leaving the default Free-plan Subscription the Organisation hook creates untouched, and switch billing-test.pw.ts to that user. beep boop
…ebee Keep initChargebee focused on the one-time init (init, checkout callbacks, plan-cookie flow) and let the exported entry point read as what callers are actually asking for — wire the currently rendered Chargebee buttons. beep boop
Zaimwa9
left a comment
There was a problem hiding this comment.
thanks! 💯
Good call to separate user and orgs in the seed
Thanks for submitting a PR! Please check the boxes below:
docs/if required so people know about the feature.Changes
Contributes to https://github.com/Flagsmith/flagsmith-private/issues/122
On the organisation Billing tab, the "14 Day Free Trial" buttons only work on first page load in Yearly mode. Toggling to Monthly — or back to Yearly — leaves the buttons inert.
Chargebee binds click handlers to
[data-cb-type="checkout"]elements whenChargebee.registerAgain()scans the DOM.initChargebeewas guarded by a one-shotinitialisedflag, soregisterAgain()only ran once. The toggle inPayment.tsxremountsPaymentButton(itskeyis thedata-cb-plan-id), and the freshly rendered buttons never get wired up.Fix: keep the one-time work (
Chargebee.init, first-promoter, checkout callbacks, plan-cookie flow) behind theinitialisedguard, split it out asinitChargebee, and have the new exportedbindChargebeeButtonscallChargebee.registerAgain()on every entry. Addyearlyto the effect's dependency array so the scan re-runs after the toggle.Also adds a new
@saasE2E marker for SaaS-only tests (billing, trials, payments), wired into the staging and production E2E runs, and a dedicatede2e_billing_userseeded on a Free-plan organisation so the trial-button path under test is actually reachable.How did you test this code?
Added
frontend/e2e/tests/billing-test.pw.ts(tagged@saas). It logs in ase2e_billing_user, stubswindow.ChargebeeviaaddInitScriptsoregisterAgain()records whichdata-cb-plan-idis clicked, and asserts the trial button fires a checkout in yearly → monthly → yearly order. Without the fix the second click records nothing; with the fix all three are recorded.Ran the test manually against real Vercel deployments:
staging.flagsmith.com(main, unfixed) — test fails at the expected assertion. Yearly click recordsstartup-annual-v2, toggle to monthly, click records nothing:["startup-annual-v2"]vs expected["startup-annual-v2", "startup-v2"]. Bug reproduced.Manual smoke in-browser: billing tab, click "14 Day Free Trial" in yearly (opens checkout), toggle to monthly and click (opens checkout), toggle back to yearly and click (opens checkout).
Follow-up
Hooking
@saastests up to run against Vercel PR previews on every PR (not just staging/prod deploys) will come in a separate PR — it needs a workflow that waits for the Vercel preview to finish and passes its URL to the composite E2E action, which is out of scope for this bug fix.