From 152561fa5654302440ad8fee1f1d2dd9da954a52 Mon Sep 17 00:00:00 2001 From: Dante Date: Wed, 2 Sep 2026 22:45:07 +0000 Subject: [PATCH] fix(billing): obtain a server quote before the team confirmation step (#16647) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary With embedded checkout off, the Team confirmation step opened before any quote was requested — so "Total due today" rendered with no amount, and a plan change that could not be priced emptied the dialog entirely. Found on staging during 1.52 QA (Denys), after #16517 fixed the same symptom for Personal. ## Root cause `handleSubscribeTeamClick`'s legacy branch set the step *before* fetching, and then usually never fetched: ```ts checkoutStep.value = 'preview' // step first const needsPreview = payload.isChange || isSubscriptionCancelled() if (!needsPreview || !payload.stop.id) return // fresh subscribe: no request at all ``` `previewData` is reset to `null` immediately above this, so a fresh team subscribe reached the confirmation with no quote. `SubscriptionAddPaymentPreviewWorkspace` renders the total from `previewData`, so the amount and the whole renewal line came out empty. Everything else on that screen ($665, billing cycle, refill credits) is derived from the `teamPlan` prop, which is why the screen looked otherwise healthy. Personal was never affected: `handleSubscribeClick` calls `previewSubscribe` on both sides of the flag and only then advances the step. So #16517 (legacy quote formatting) could not have fixed Team — there was no preview to format. The same early step change produced the empty modal on Team → Change plan. `previewVariant` returns `'team-change'` from `checkoutType` alone, and the two exits at `if (!payload.stop.id) return` and `if (!isSubscriptionCancelled()) return` leave `previewData` null. `SubscriptionTransitionPreviewWorkspace` declares `previewData: PreviewSubscribeResponse` (required) and dereferences it during setup (`previewData.promotion_code`), so setup throws and only the dialog chrome renders. The `:preview-data="previewData!"` assertion at the call site is what kept this off the type checker. ## Changes - **What**: the legacy team path fetches and installs the preview first, and advances to the confirmation only when `isUsableTeamPreview` accepts it — otherwise it reports the failure and stays on pricing, matching the personal and embedded paths. Removed the `previewData!` assertions so a null preview can no longer reach a required prop. The total row is omitted rather than rendered blank when nothing can price it (the id-less OSS stop, the one case with no server quote available). - **Breaking**: a preview failure now blocks a fresh team subscribe instead of showing an unpriced confirmation. This matches what the flag-on path already does. ## Review Focus `isUsableTeamPreview` keeps the three acceptance rules that were previously inline and adds the new-subscription case, which had no rule because it never fetched: cancelled needs a reactivation-capable preview, a change needs an existing-plan transition, a new subscribe needs any allowed preview. Worth knowing for the release call: `embeddedCheckoutEnabled` appears exactly once in `useSubscriptionCheckout.test.ts` — as the `setup()` default of `true`. Every one of the 131 existing tests ran the flag-on branch, so the entire legacy branch shipped uncovered. That is the actual reason this reached staging, and the four new tests are scoped to it. Amounts stay server-resolved throughout; nothing here derives a price from `teamPlan`. - Fixes FE-1974 ## Screenshots (if applicable) Captured against a cloud-distribution dev server with embedded checkout off, driving the real flow: Settings → Plan & Credits → Change plan → pick a different Team credit stop → Change plan. ### AS IS — `main` ![AS IS: the change-plan confirmation is an empty "Choose a Plan" box](https://raw.githubusercontent.com/dante01yoon/ComfyUI_frontend/assets/pr-16647-screenshots/docs-assets/pr-16647/asis-change-plan-empty.png) The step is entered with `previewData` still null. `SubscriptionTransitionPreviewWorkspace` declares that prop required and dereferences it during setup, so setup throws and the body renders nothing — only the shell's own header is left. This is the same failure QA hit on staging. ### TO BE — this PR > This shot still shows a duplicated "Choose a Plan" header and a second back arrow. That is a separate defect, fixed in #16648 — it is left visible here so this PR's own contribution is legible on its own. ![TO BE: the confirmation renders with Total due today priced from the server](https://raw.githubusercontent.com/dante01yoon/ComfyUI_frontend/assets/pr-16647-screenshots/docs-assets/pr-16647/tobe-change-plan-priced.png) The preview is fetched and installed before the step is entered, so the confirmation renders and `Total due today` is priced from the server's legacy `cost_*` fields — $361.00 here, with the renewal line resolved too. ### TO BE — with #16648 applied as well ![TO BE: a single header and one back action, with the amount priced](https://raw.githubusercontent.com/dante01yoon/ComfyUI_frontend/assets/pr-16647-screenshots/docs-assets/pr-16647/tobe-both-prs.png) How the step looks once both PRs are in. They are two halves of the same report and ship together for 1.52. --- .../dialogs/pricingTableDeepLink.spec.ts | 61 ++++++++++++++ ...criptionAddPaymentPreviewWorkspace.test.ts | 12 +++ ...SubscriptionAddPaymentPreviewWorkspace.vue | 1 + ...iptionRequiredDialogContentUnified.test.ts | 25 +++++- ...bscriptionRequiredDialogContentUnified.vue | 8 +- .../useSubscriptionCheckout.test.ts | 79 +++++++++++++++++++ .../composables/useSubscriptionCheckout.ts | 38 ++++++--- 7 files changed, 205 insertions(+), 19 deletions(-) diff --git a/browser_tests/tests/dialogs/pricingTableDeepLink.spec.ts b/browser_tests/tests/dialogs/pricingTableDeepLink.spec.ts index 35c9b8c7c00..54dfbbac386 100644 --- a/browser_tests/tests/dialogs/pricingTableDeepLink.spec.ts +++ b/browser_tests/tests/dialogs/pricingTableDeepLink.spec.ts @@ -193,6 +193,60 @@ const TEAM_SUBSCRIBED_RESPONSE = { effective_at: '2026-07-21T00:00:00Z' } satisfies SubscribeResponse +const TEAM_ANNUAL_PLAN = { + slug: 'team_per_credit_annual', + tier: 'TEAM', + duration: 'ANNUAL', + price_cents: 756_000, + credits_cents: 1_772_400, + max_seats: 100, + availability: { available: true }, + seat_summary: { + seat_count: 1, + total_cost_cents: 756_000, + total_credits_cents: 1_772_400 + } +} satisfies Plan + +const TEAM_MONTHLY_PLAN = { + slug: 'team_per_credit_monthly', + tier: 'TEAM', + duration: 'MONTHLY', + price_cents: 39_000, + credits_cents: 84_400, + max_seats: 100, + availability: { available: true }, + seat_summary: { + seat_count: 1, + total_cost_cents: 39_000, + total_credits_cents: 84_400 + } +} satisfies Plan + +const NEW_TEAM_ANNUAL_SUBSCRIPTION = { + allowed: true, + transition_type: 'new_subscription', + effective_at: '2026-07-21T00:00:00Z', + is_immediate: true, + cost_today_cents: 756_000, + cost_next_period_cents: 756_000, + credits_today_cents: 1_772_400, + credits_next_period_cents: 1_772_400, + new_plan: TEAM_ANNUAL_PLAN +} satisfies PreviewSubscribeResponse + +const NEW_TEAM_MONTHLY_SUBSCRIPTION = { + allowed: true, + transition_type: 'new_subscription', + effective_at: '2026-07-21T00:00:00Z', + is_immediate: true, + cost_today_cents: 39_000, + cost_next_period_cents: 39_000, + credits_today_cents: 84_400, + credits_next_period_cents: 84_400, + new_plan: TEAM_MONTHLY_PLAN +} satisfies PreviewSubscribeResponse + const NEW_CREATOR_SUBSCRIPTION = { allowed: true, transition_type: 'new_subscription', @@ -711,6 +765,9 @@ test.describe('Pricing table deep link', { tag: '@cloud' }, () => { await page.route('**/api/billing/plans', (route) => route.fulfill(jsonRoute(TEAM_CATALOG_PLANS)) ) + await page.route('**/api/billing/preview-subscribe', (route) => + route.fulfill(jsonRoute(NEW_TEAM_ANNUAL_SUBSCRIPTION)) + ) await page.route('**/api/billing/subscribe', (route) => { subscribeRequests.push(route.request()) return route.fulfill(jsonRoute(TEAM_SUBSCRIBED_RESPONSE)) @@ -759,6 +816,10 @@ test.describe('Pricing table deep link', { tag: '@cloud' }, () => { route.fulfill(jsonRoute(TEAM_CATALOG_PLANS)) ) + await page.route('**/api/billing/preview-subscribe', (route) => + route.fulfill(jsonRoute(NEW_TEAM_MONTHLY_SUBSCRIPTION)) + ) + await page.goto(`${APP_URL}/?pricing=team&stop=team_400&cycle=monthly`) await cloudAppExpect( diff --git a/src/platform/workspace/components/SubscriptionAddPaymentPreviewWorkspace.test.ts b/src/platform/workspace/components/SubscriptionAddPaymentPreviewWorkspace.test.ts index 528b97b2e02..d08423c1eb8 100644 --- a/src/platform/workspace/components/SubscriptionAddPaymentPreviewWorkspace.test.ts +++ b/src/platform/workspace/components/SubscriptionAddPaymentPreviewWorkspace.test.ts @@ -419,6 +419,18 @@ describe('SubscriptionAddPaymentPreviewWorkspace', () => { expect(emitted().back).toBeTruthy() }) + it('omits the total row entirely when no quote is available to price it', () => { + render(SubscriptionAddPaymentPreviewWorkspace, { + props: { + teamPlan: { usd: 700, credits: 147_700, discountedUsd: 665 }, + previewData: null + }, + global: globalOptions + }) + + expect(screen.queryByText('subscription.preview.totalDueToday')).toBeNull() + }) + it('prices a legacy preview from the server costs instead of rendering a blank total', () => { const { amount_due_cents, diff --git a/src/platform/workspace/components/SubscriptionAddPaymentPreviewWorkspace.vue b/src/platform/workspace/components/SubscriptionAddPaymentPreviewWorkspace.vue index e82bb75cb06..73d4863d6cc 100644 --- a/src/platform/workspace/components/SubscriptionAddPaymentPreviewWorkspace.vue +++ b/src/platform/workspace/components/SubscriptionAddPaymentPreviewWorkspace.vue @@ -100,6 +100,7 @@
Back
` }, - SubscriptionTransitionPreviewWorkspace: { template: '
' }, + SubscriptionTransitionPreviewWorkspace: { + template: '
' + }, SubscriptionSuccessWorkspace: { template: '
' } } } @@ -251,6 +253,25 @@ describe('SubscriptionRequiredDialogContentUnified team-plan subscribe', () => { expect(mockHandleSubscribeClick).not.toHaveBeenCalled() }) + it.for(['team-change', 'personal-change'])( + 'withholds the transition confirm until its preview arrives (%s)', + async (previewVariant) => { + mockCheckoutStep.value = 'preview' + mockPreviewVariant.value = previewVariant + mockSelectedTeamStop.value = TEAM_PAYLOAD.stop + mockPreviewData.value = null + + renderComponent() + + expect(screen.queryByTestId('transition-preview')).toBeNull() + + mockPreviewData.value = { amount_due_cents: 1600, currency: 'usd' } + await nextTick() + + expect(screen.getByTestId('transition-preview')).toBeTruthy() + } + ) + it.for([true, false])( 'leaves the confirm step its own header and back action (embedded: %s)', async (embeddedCheckoutEnabled) => { diff --git a/src/platform/workspace/components/SubscriptionRequiredDialogContentUnified.vue b/src/platform/workspace/components/SubscriptionRequiredDialogContentUnified.vue index 77d8fbc2d2d..81255fe5737 100644 --- a/src/platform/workspace/components/SubscriptionRequiredDialogContentUnified.vue +++ b/src/platform/workspace/components/SubscriptionRequiredDialogContentUnified.vue @@ -73,8 +73,8 @@