From 4e6511fbb6943fc2e42df967962107c6c1e241b0 Mon Sep 17 00:00:00 2001 From: Dante Date: Fri, 25 Sep 2026 03:05:35 +0000 Subject: [PATCH] FE-2767 fix(billing-web): confirm scheduled plan changes without a card form (#18684) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary `CheckoutView.vue` always mounted `StripePaymentForm`, so any plan change on an existing subscription that doesn't need a new card (a scheduled/duration change, or any upgrade/downgrade — Stripe charges the subscription's saved default method server-side) showed "The payment form isn't available right now" with "Pay and subscribe" disabled, blocking the customer entirely. ## Why A customer on a subscribed Team workspace could not complete a scheduled plan change on billing-web at all. The page rendered a payment form that could never succeed, with no way to confirm a change that in fact required no payment today. ## Root cause Live testing on testcloud/testbilling: a subscribed Team workspace (yearly, `team_700` stop) changing to monthly hands off to billing-web's `/v1/checkout?...&team_credit_stop_id=team_700`. `POST /api/billing/preview-subscribe` returns `transition_type: "duration_change"`, `is_immediate: false`, $0 due today, and no `payment_method_configuration_id`. `CheckoutView.vue` mounted `StripePaymentForm` unconditionally; that component hard-fails (`failElementInit()`, `packages/account-ui/src/billing/stripe/StripePaymentForm.vue:217`) whenever `paymentMethodConfigurationId` is empty. The Cloud app already solves this correctly: `src/platform/workspace/composables/useSubscriptionCheckout.ts`'s `subscribeAcceptsSavedMethod()` and its accompanying comment state that "the transition workflows charge the subscription's existing default method and reject a payment-method selection outright" — any `transition_type` other than `'new_subscription'` skips card capture and confirms straight against the saved method. `SubscriptionTransitionPreviewWorkspace.vue` (confirm-only) vs `SubscriptionAddPaymentPreviewWorkspace.vue` (card capture) branch on exactly that field. ## How `CheckoutView.vue` now branches on `preview.transition_type === 'new_subscription'` (`needsPaymentMethod`), the same signal the Cloud app already ships, read straight off the required, non-optional `transition_type` field — no guessing from `payment_method_configuration_id`'s presence, which is ambiguous (see Backend dependency below). When a card is needed, the existing `StripePaymentForm` path is unchanged, including the 3DS/result flow. When it isn't, a plain confirm form calls the same `checkout.subscribe`/`subscribeRequest`, just without a `confirmation_token` — `zSubscribeRequest.confirmation_token` is already optional, so no new command was needed. Test default fixtures (`previewOf()` in `fakeBillingClient.ts`, the e2e `scenario.preview`) moved from `transition_type: 'upgrade'` to `'new_subscription'`, since that's what most existing tests actually exercise (card entry). Tests that specifically cover a transition now set `transition_type` explicitly. Added table-driven coverage (`it.for`) for upgrade/downgrade/duration_change confirming without a card form, and an e2e case in `checkout.spec.ts`. `subscription.spec.ts`'s "choosing a plan... continues to checkout" test previously asserted the exact bug ("The payment form isn't available right now" was the *expected* outcome for an upgrade) — updated to assert the fixed confirm-only UI instead. ## Backend dependency Separately, on testcloud a brand-new subscription (`transition_type: "new_subscription"`, `is_immediate: true`, real cost) can *also* come back with no `payment_method_configuration_id`, because `services/ingest/server/implementation/billing.go` only calls `attachPaymentMethodConfiguration` when the per-user `embedded_checked_enabled` PostHog flag is on. billing-web always renders the embedded Stripe form (it has no non-embedded fallback the way the Cloud app might), so a user outside that flag still hits "payment form isn't available" on a genuine new-subscription checkout. This PR doesn't work around that on the frontend — the server needs to attach the payment method configuration for billing-web requests unconditionally (or expose an explicit flag), independent of `embedded_checked_enabled`. ## Changes - **What**: `CheckoutView.vue` renders a confirm-only path (summary + button, no Stripe form) when the preview's `transition_type` isn't `new_subscription`; `subscribeRequest`/`confirm` accept an optional `confirmationToken`. - **Dependencies**: none. ## Review Focus The `transition_type` condition and whether it should live in `account-ui` instead (kept in `CheckoutView.vue` per ADR-PACKAGES-ACCOUNT-UI-0034 — it's not Stripe-provider-bound, so nothing in the ADR forces promotion, and the change stays minimal). The Backend dependency note above — flagging it, not fixing it here. ## AS IS / TO BE | AS IS | TO BE | | --- | --- | | AS IS | TO BE | Personal Workspace with an active `team_per_credit_annual` / `team_700` subscription, opening `/v1/checkout?product=comfyui&return_to=comfyui_workspace&plan=team_per_credit_monthly&team_credit_stop_id=team_700` against testcloud. `POST /api/billing/preview-subscribe` returns `transition_type: "duration_change"`, `is_immediate: false`, `cost_today_cents: 0`. - AS IS: https://testbilling.comfy.org (main build). The payment section never renders a card form and "Pay and subscribe" stays disabled (still disabled after 30s, no Stripe frame mounted). The preview now carries a `payment_method_configuration_id`, so the "payment form isn't available" copy from the original report did not show on this run, but the customer is still blocked. - TO BE: this branch on http://localhost:5174. Confirm-only form: summary plus an enabled "Pay and subscribe", no card form. The button was not clicked, so the subscription was not changed. - Fixes #ISSUE_NUMBER ## Plan position: Milestone 2 payment-test fixes Found in the live M2 run (testcloud → testbilling, Team per-credit checkout). None of these PRs depends on another to merge. Solid arrows gate a milestone step; dotted ones are nice-to-have. | PR | Defect | Dependency | |---|---|---| | [D5 cloud#10518](https://github.com/Comfy-Org/cloud/pull/10518) | test-v2 billing-worker uses the wrong Stripe key; every confirm fails `parameter_missing client_secret` | Blocker on test only (config). Unblocks the live re-run. | | [D4 cloud#10514](https://github.com/Comfy-Org/cloud/pull/10514) | preview-subscribe attaches `payment_method_configuration_id` only when `embedded_checked_enabled` is on | Required before widening `hosted_billing_destination` past the flag cohort. | | **[D3 FE #18684](https://github.com/Comfy-Org/ComfyUI_frontend/pull/18684) (this PR)** | billing-web asks for a card on plan changes that need none | Independent. Shares e2e fixtures with #18687. | | [D6 FE #18687](https://github.com/Comfy-Org/ComfyUI_frontend/pull/18687) | failed-payment UI ignores `recovery_action` / `retryable` | Independent. Shares e2e fixtures with #18684. | | [D8 FE #18686](https://github.com/Comfy-Org/ComfyUI_frontend/pull/18686) | Stripe Element labels invisible in dark theme | Independent (cosmetic). | | [D7 FE #18685](https://github.com/Comfy-Org/ComfyUI_frontend/pull/18685) | billing-web font URL broken (`/fonts/inter-*.woff2`) | Independent (cosmetic). | ```mermaid flowchart LR c10518["D5 cloud#10518
test-v2 Stripe key"] c10514["D4 cloud#10514
always attach pmc id"] f18684["D3 #18684
no card for plan change"] f18687["D6 #18687
recovery_action UI"] f18686["D8 #18686
dark-theme labels"] f18685["D7 #18685
fonts"] RERUN(["M2 live payment re-run
testcloud → testbilling"]) ROLLOUT(["Widen hosted_billing_destination
beyond flag cohort"]) c10518 --> RERUN c10514 --> ROLLOUT f18684 --> ROLLOUT f18687 --> ROLLOUT f18686 -.-> ROLLOUT f18685 -.-> ROLLOUT RERUN --> ROLLOUT f18684 <-. "shared e2e fixtures:
second to merge pulls main" .-> f18687 style f18684 fill:#f9d71c,stroke:#333,stroke-width:3px,color:#000 ``` --- apps/billing-web/e2e/checkout.spec.ts | 36 +++++++++ apps/billing-web/e2e/fixtures/scenario.ts | 2 +- apps/billing-web/e2e/subscription.spec.ts | 14 +++- .../src/components/CheckoutPayment.vue | 80 +++++++++++++++++++ .../billing-web/src/test/fakeBillingClient.ts | 2 +- .../src/views/CheckoutView.test.ts | 43 +++++++++- apps/billing-web/src/views/CheckoutView.vue | 50 +++++++----- .../src/views/SubscriptionView.test.ts | 7 +- 8 files changed, 207 insertions(+), 27 deletions(-) create mode 100644 apps/billing-web/src/components/CheckoutPayment.vue diff --git a/apps/billing-web/e2e/checkout.spec.ts b/apps/billing-web/e2e/checkout.spec.ts index bcb57446067..a013ec88143 100644 --- a/apps/billing-web/e2e/checkout.spec.ts +++ b/apps/billing-web/e2e/checkout.spec.ts @@ -89,6 +89,42 @@ test('submitting payment carries the idempotency key and plan, and settles as su expect(await fakeStripeCalls(page, 'nextActions')).toBe(0) }) +test('a scheduled plan change confirms against the saved payment method, no card form', async ({ + page, + cloud, + signIn +}) => { + cloud.scenario.preview = { + ...cloud.scenario.preview, + transition_type: 'duration_change', + is_immediate: false, + cost_today_cents: 0, + amount_due_cents: 0 + } + await signIn(CHECKOUT) + + await expect( + page.getByRole('button', { name: 'Pay and subscribe' }) + ).toBeVisible() + await expect(page.getByText('Pro · Monthly')).toBeVisible() + + await page.getByRole('button', { name: 'Pay and subscribe' }).click() + + await expect( + page.getByRole('heading', { name: "You're all set" }) + ).toBeVisible() + + const subscribe = cloud.requests.find( + (request) => request.path === '/billing/subscribe' + ) + expect(subscribe?.body).toMatchObject({ plan_slug: 'pro_monthly' }) + expect(subscribe?.body).not.toHaveProperty('confirmation_token') + + // The fake only installs itself once the app requests js.stripe.com, so + // its absence proves Stripe.js was never loaded for this path. + expect(await page.evaluate('window.__e2eFakeStripe')).toBeUndefined() +}) + test('a declined payment shows the reason and stays on checkout', async ({ page, cloud, diff --git a/apps/billing-web/e2e/fixtures/scenario.ts b/apps/billing-web/e2e/fixtures/scenario.ts index 7e1556f35d1..8f106fc9a20 100644 --- a/apps/billing-web/e2e/fixtures/scenario.ts +++ b/apps/billing-web/e2e/fixtures/scenario.ts @@ -155,7 +155,7 @@ export function defaultScenario(): CloudScenario { ], preview: { allowed: true, - transition_type: 'upgrade', + transition_type: 'new_subscription', is_immediate: true, effective_at: new Date().toISOString(), renewal_at: inAnHour(), diff --git a/apps/billing-web/e2e/subscription.spec.ts b/apps/billing-web/e2e/subscription.spec.ts index 1291a3626a3..9862b01bf92 100644 --- a/apps/billing-web/e2e/subscription.spec.ts +++ b/apps/billing-web/e2e/subscription.spec.ts @@ -32,6 +32,10 @@ test('choosing a plan quotes it from the server and continues to checkout', asyn cloud, signIn }) => { + cloud.scenario.preview = { + ...cloud.scenario.preview, + transition_type: 'upgrade' + } await signIn(SUBSCRIPTION) await page.getByRole('button', { name: 'Choose Pro · Monthly' }).click() @@ -54,11 +58,15 @@ test('choosing a plan quotes it from the server and continues to checkout', asyn ).toBeVisible() await expect(page.getByText('Pro · Monthly')).toBeVisible() await expect(page.getByText('Total due today')).toBeVisible() + // An upgrade on an existing subscription charges the saved payment method + // server-side, so no card form is needed here — see checkout.spec.ts for + // that path's full coverage. await expect( - page.getByText("The payment form isn't available right now.", { - exact: false - }) + page.getByRole('button', { name: 'Pay and subscribe' }) ).toBeVisible() + await expect( + page.getByText("The payment form isn't available right now.") + ).not.toBeVisible() }) test('a checkout link naming a team credit stop quotes it along with the plan', async ({ diff --git a/apps/billing-web/src/components/CheckoutPayment.vue b/apps/billing-web/src/components/CheckoutPayment.vue new file mode 100644 index 00000000000..7e53c4f72dc --- /dev/null +++ b/apps/billing-web/src/components/CheckoutPayment.vue @@ -0,0 +1,80 @@ + + + diff --git a/apps/billing-web/src/test/fakeBillingClient.ts b/apps/billing-web/src/test/fakeBillingClient.ts index 0b5b4e62f7d..e6587939361 100644 --- a/apps/billing-web/src/test/fakeBillingClient.ts +++ b/apps/billing-web/src/test/fakeBillingClient.ts @@ -289,7 +289,7 @@ export function previewOf( credits_next_period_cents: 6900, effective_at: '2026-10-01T00:00:00.000Z', is_immediate: true, - transition_type: 'upgrade', + transition_type: 'new_subscription', new_plan: { credits_cents: 6900, duration: 'MONTHLY', diff --git a/apps/billing-web/src/views/CheckoutView.test.ts b/apps/billing-web/src/views/CheckoutView.test.ts index a2cf17ab113..0a18458a0a2 100644 --- a/apps/billing-web/src/views/CheckoutView.test.ts +++ b/apps/billing-web/src/views/CheckoutView.test.ts @@ -90,7 +90,10 @@ vi.mock(import('@/session/stripeChallengePort'), () => ({ * The provider form is covered in the package against the real Stripe mocks. * Here it records what it was handed and lets a test hand back a token. */ -const formProps = vi.hoisted(() => ({ value: {} as Record })) +const formProps = vi.hoisted(() => ({ + value: {} as Record, + mounted: false +})) let reportConfirm: (confirmationToken: string) => void = () => {} vi.mock(import('@comfyorg/account-ui/billing/stripe'), () => ({ @@ -117,6 +120,7 @@ vi.mock(import('@comfyorg/account-ui/billing/stripe'), () => ({ } ) { formProps.value = props + formProps.mounted = true reportConfirm = (token) => emit('confirm', token) return () => slots.submit?.({ disabled: !props.canSubmit, loading: props.isLoading }) @@ -167,6 +171,7 @@ describe('CheckoutView', () => { beforeEach(() => { workspace.session = undefined workspace.bound = undefined + formProps.mounted = false }) it('quotes the plan the link names and prices the summary from it', async () => { @@ -628,6 +633,42 @@ describe('CheckoutView', () => { ) }) + it.for([ + ['upgrade', true, 2800] as const, + ['downgrade', true, 1400] as const, + ['duration_change', false, 0] as const + ])( + 'confirms a %s plan change against the saved payment method, no card form', + async ([transitionType, isImmediate, costTodayCents]) => { + const fake = await renderCheckout(CHECKOUT_PATH, { + preview: { + status: 'ok', + value: previewOf({ + transition_type: transitionType, + is_immediate: isImmediate, + cost_today_cents: costTodayCents, + amount_due_cents: costTodayCents + }) + } + }) + const pay = await screen.findByRole('button', { + name: 'Pay and subscribe' + }) + expect(formProps.mounted).toBe(false) + + await userEvent.click(pay) + + await waitFor(() => + expect(fake.subscribe).toHaveBeenCalledWith( + expect.objectContaining({ plan_slug: 'creator_monthly' }) + ) + ) + expect(fake.subscribe.mock.calls[0][0]).not.toHaveProperty( + 'confirmation_token' + ) + } + ) + it('explains a quote the server refused and offers the way back', async () => { await renderCheckout(CHECKOUT_PATH, { preview: { status: 'error', code: 'NO_ACTIVE_SUBSCRIPTION' } diff --git a/apps/billing-web/src/views/CheckoutView.vue b/apps/billing-web/src/views/CheckoutView.vue index 88db09041b4..4b1cbb16458 100644 --- a/apps/billing-web/src/views/CheckoutView.vue +++ b/apps/billing-web/src/views/CheckoutView.vue @@ -20,14 +20,13 @@ import { usePreviewSubscribe } from '@comfyorg/account-ui/billing' import type { StripePaymentCopy } from '@comfyorg/account-ui/billing/stripe' -import { StripePaymentForm } from '@comfyorg/account-ui/billing/stripe' import { billingIntentPath, buildBillingEntryUrl, buildReturnUrl } from '@comfyorg/billing-contract' -import CheckoutSubmit from '@/components/CheckoutSubmit.vue' +import CheckoutPayment from '@/components/CheckoutPayment.vue' import EmbeddedCheckout from '@/components/EmbeddedCheckout.vue' import HostedSurface from '@/components/HostedSurface.vue' import { useBilledWorkspace } from '@/composables/useBilledWorkspace' @@ -168,6 +167,17 @@ const paymentMethodConfigurationId = computed( () => preview.value?.payment_method_configuration_id ?? '' ) +/** + * A plan change on an existing subscription charges its saved default + * payment method server-side and never accepts a new one (the ingest + * `subscribeAcceptsSavedMethod` comment in useSubscriptionCheckout.ts states + * this outright); only a genuine new subscription has no saved method yet, + * so only that transition needs the card form. + */ +const needsPaymentMethod = computed( + () => preview.value?.transition_type === 'new_subscription' +) + const publishableKey = computed(() => stripeKey.value ?? '') const quoting = computed(() => loading.value && summary.value === undefined) @@ -210,16 +220,23 @@ function resultUrl(): string | undefined { return built.status === 'ok' ? built.url.href : undefined } -/** The quote's identity travels with the charge, so the server prices what the customer saw. */ +/** + * The quote's identity travels with the charge, so the server prices what + * the customer saw. A plan change on an existing subscription (see + * `needsPaymentMethod`) has no `confirmationToken` — the server charges the + * saved method on file instead. + */ function subscribeRequest( plan: string, - confirmationToken: string, + confirmationToken: string | undefined, quoted: SubscriptionPreview ): SubscribeInput { const returnUrl = resultUrl() return { plan_slug: plan, - confirmation_token: confirmationToken, + ...(confirmationToken === undefined + ? {} + : { confirmation_token: confirmationToken }), ...(teamCreditStopId.value === undefined ? {} : { team_credit_stop_id: teamCreditStopId.value }), @@ -235,7 +252,7 @@ function subscribeRequest( } } -async function confirm(confirmationToken: string) { +async function confirm(confirmationToken?: string) { const quoted = preview.value if (planSlug.value === undefined || !quoted || loading.value) return submitFailure.value = undefined @@ -336,28 +353,21 @@ const subscriptionPath = computed(() => ({ @cancel="checkout.cancel()" @continue-verification="checkout.continueVerification()" /> - - - + />