From 6a6532fa2719dc5ee9f9cf20610dca27f4ef68ec Mon Sep 17 00:00:00 2001 From: dante01yoon Date: Mon, 28 Sep 2026 13:31:29 -0400 Subject: [PATCH 01/18] feat(account-ui): export CheckoutTermsNote from the checkout entry The full-page checkout lays out its own pay action and needs the shared terms line with its Terms and Privacy Policy links, rather than a copy of it. --- packages/account-ui/src/billing/checkout/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/account-ui/src/billing/checkout/index.ts b/packages/account-ui/src/billing/checkout/index.ts index 370c998ff7c..c8ae25e66a8 100644 --- a/packages/account-ui/src/billing/checkout/index.ts +++ b/packages/account-ui/src/billing/checkout/index.ts @@ -25,4 +25,5 @@ export { export { default as CheckoutPaymentForm } from './CheckoutPaymentForm.vue' export { default as CheckoutSubscribeConfirm } from './CheckoutSubscribeConfirm.vue' export { default as CheckoutSuccess } from './CheckoutSuccess.vue' +export { default as CheckoutTermsNote } from './CheckoutTermsNote.vue' export { default as CheckoutTransitionConfirm } from './CheckoutTransitionConfirm.vue' From 6332692170e5f0b5ff9e7a55fa0d65cd7a2ece2c Mon Sep 17 00:00:00 2001 From: dante01yoon Date: Mon, 28 Sep 2026 13:41:48 -0400 Subject: [PATCH 02/18] feat(billing-web): full-page checkout shell, eyebrow and capture skeleton Behind billing_web_checkout_ui=full_page. useFullPageCheckout reads capabilities, the quote and the Stripe key on arrival and drives the CheckoutPage reducer: a denial renders a refusal placeholder, a failed read says so, and the skeleton holds real chrome with data bars and a disabled Pay. Pay enables only once the quote has arrived and the Stripe payment element reports ready, and locks once an operation starts. A failed element replaces the whole payment column with a Try again that remounts it. Pay subscribes through useCheckout with the quoted plan. --- .../components/fullPage/CheckoutPayAction.vue | 47 +++ .../fullPage/CheckoutPaymentColumn.vue | 94 +++++ .../fullPage/CheckoutSummaryColumn.vue | 78 +++++ .../components/fullPage/PaymentFormError.vue | 33 ++ .../src/composables/useFullPageCheckout.ts | 183 ++++++++++ apps/billing-web/src/locales/en/main.json | 29 +- .../src/views/FullPageCheckoutView.test.ts | 331 ++++++++++++++++++ .../src/views/FullPageCheckoutView.vue | 129 ++++++- 8 files changed, 918 insertions(+), 6 deletions(-) create mode 100644 apps/billing-web/src/components/fullPage/CheckoutPayAction.vue create mode 100644 apps/billing-web/src/components/fullPage/CheckoutPaymentColumn.vue create mode 100644 apps/billing-web/src/components/fullPage/CheckoutSummaryColumn.vue create mode 100644 apps/billing-web/src/components/fullPage/PaymentFormError.vue create mode 100644 apps/billing-web/src/composables/useFullPageCheckout.ts create mode 100644 apps/billing-web/src/views/FullPageCheckoutView.test.ts diff --git a/apps/billing-web/src/components/fullPage/CheckoutPayAction.vue b/apps/billing-web/src/components/fullPage/CheckoutPayAction.vue new file mode 100644 index 00000000000..160880e7415 --- /dev/null +++ b/apps/billing-web/src/components/fullPage/CheckoutPayAction.vue @@ -0,0 +1,47 @@ + + + diff --git a/apps/billing-web/src/components/fullPage/CheckoutPaymentColumn.vue b/apps/billing-web/src/components/fullPage/CheckoutPaymentColumn.vue new file mode 100644 index 00000000000..5cc9409e6cf --- /dev/null +++ b/apps/billing-web/src/components/fullPage/CheckoutPaymentColumn.vue @@ -0,0 +1,94 @@ + + + diff --git a/apps/billing-web/src/components/fullPage/CheckoutSummaryColumn.vue b/apps/billing-web/src/components/fullPage/CheckoutSummaryColumn.vue new file mode 100644 index 00000000000..cf65a72dd8d --- /dev/null +++ b/apps/billing-web/src/components/fullPage/CheckoutSummaryColumn.vue @@ -0,0 +1,78 @@ + + + diff --git a/apps/billing-web/src/components/fullPage/PaymentFormError.vue b/apps/billing-web/src/components/fullPage/PaymentFormError.vue new file mode 100644 index 00000000000..37453a1726a --- /dev/null +++ b/apps/billing-web/src/components/fullPage/PaymentFormError.vue @@ -0,0 +1,33 @@ + + + diff --git a/apps/billing-web/src/composables/useFullPageCheckout.ts b/apps/billing-web/src/composables/useFullPageCheckout.ts new file mode 100644 index 00000000000..2ff1c773f3e --- /dev/null +++ b/apps/billing-web/src/composables/useFullPageCheckout.ts @@ -0,0 +1,183 @@ +import { computed, shallowReadonly, shallowRef } from 'vue' + +import type { + SubscribeInput, + SubscriptionPreview +} from '@comfyorg/account-core/billing' +import { + useBillingClient, + useCheckout, + usePreviewSubscribe +} from '@comfyorg/account-ui/billing' +import type { StripePaymentPhase } from '@comfyorg/account-ui/billing/stripe' +import type { BillingEntry } from '@comfyorg/billing-contract' +import { + buildBillingEntryUrl, + buildReturnUrl +} from '@comfyorg/billing-contract' + +import type { CheckoutPage, CheckoutPageEvent } from '@/checkout/checkoutPage' +import { + RESOLVING, + railAcceptsPay, + reduceCheckoutPage +} from '@/checkout/checkoutPage' +import { useBilledWorkspace } from '@/composables/useBilledWorkspace' +import { BILLING_WEB_ENV } from '@/config/env' +import { awaitBillingWebStripeKey } from '@/config/stripeKey' +import { useBillingEntry } from '@/entry/billingEntry' +import { createDeferredStripeChallengePort } from '@/session/stripeChallengePort' + +/** + * The full-page checkout's effects around one `CheckoutPage` state: the + * capabilities read, the quote and the Stripe key on arrival, the payment + * element's readiness, and the subscribe on Pay. Every change goes through + * `reduceCheckoutPage`; the quote itself stays with `usePreviewSubscribe`. + * The key is awaited because the payment form reads it only when it mounts. + */ +export function useFullPageCheckout() { + const { entry } = useBillingEntry() + const billedWorkspace = useBilledWorkspace() + const { capabilities } = useBillingClient<'capabilities'>(undefined) + const { preview, quote } = usePreviewSubscribe() + const checkout = useCheckout({ + openUrl: (url) => window.location.assign(url), + navigationMode: 'redirect', + challengePort: createDeferredStripeChallengePort(awaitBillingWebStripeKey) + }) + + const page = shallowRef(RESOLVING) + + function dispatch(event: CheckoutPageEvent) { + page.value = reduceCheckoutPage(page.value, event) + } + + async function resolve(arrival: BillingEntry) { + if (arrival.plan === undefined) return + const [allowed, quoted] = await Promise.all([ + capabilities.read(), + quote({ + planSlug: arrival.plan, + ...(arrival.teamCreditStopId === undefined + ? {} + : { teamCreditStopId: arrival.teamCreditStopId }) + }), + awaitBillingWebStripeKey() + ]) + if (allowed.status === 'error') { + dispatch({ type: 'unavailable', code: allowed.code }) + } else if (!allowed.value.capabilities.can_subscribe_self_serve) { + dispatch({ + type: 'refused', + reason: allowed.value.denials.can_subscribe_self_serve ?? 'unspecified' + }) + } else if (quoted.status === 'error') { + dispatch({ type: 'unavailable', code: quoted.code }) + } else { + dispatch({ + type: 'quoted', + method: + quoted.value.transition_type === 'new_subscription' + ? 'new_card' + : 'on_file' + }) + } + } + + if (entry.value !== undefined) void resolve(entry.value) + + function onPaymentPhase(phase: StripePaymentPhase) { + if (phase.phase === 'payment_element_ready' && phase.element === 'payment') + dispatch({ type: 'elementReady' }) + else if (phase.phase === 'payment_element_failed') + dispatch({ type: 'elementFailed' }) + } + + /** A started operation keeps Pay locked, so a second click cannot charge twice. */ + const canPay = computed( + () => + railAcceptsPay(page.value) && + preview.value?.allowed === true && + checkout.operation.value === undefined + ) + + const payFailure = computed(() => + checkout.result.value?.status === 'error' + ? checkout.result.value.code + : undefined + ) + + const returnLink = computed(() => { + const arrival = entry.value + if (!arrival) return undefined + return buildReturnUrl({ + target: arrival.returnTo, + environment: BILLING_WEB_ENV, + workspace: billedWorkspace() + })?.href + }) + + /** Where a hosted payment step sends the customer back: this origin, same request. */ + function resultUrl(arrival: BillingEntry): string | undefined { + const workspaceId = billedWorkspace() + const built = buildBillingEntryUrl({ + billingOrigin: window.location.origin, + intent: 'result', + product: arrival.product, + returnTo: arrival.returnTo, + ...(arrival.plan === undefined ? {} : { plan: arrival.plan }), + ...(arrival.teamCreditStopId === undefined + ? {} + : { teamCreditStopId: arrival.teamCreditStopId }), + ...(workspaceId === undefined ? {} : { workspaceId }) + }) + return built.status === 'ok' ? built.url.href : undefined + } + + function subscribeRequest( + arrival: BillingEntry, + plan: string, + quoted: SubscriptionPreview, + confirmationToken: string | undefined + ): SubscribeInput { + const returnUrl = resultUrl(arrival) + return { + plan_slug: plan, + ...(confirmationToken === undefined + ? {} + : { confirmation_token: confirmationToken }), + ...(arrival.teamCreditStopId === undefined + ? {} + : { team_credit_stop_id: arrival.teamCreditStopId }), + ...(quoted.quote_id === undefined ? {} : { quote_id: quoted.quote_id }), + ...(quoted.quote_version === undefined + ? {} + : { quote_version: quoted.quote_version }), + ...(quoted.is_immediate && quoted.proration_at !== undefined + ? { proration_at: quoted.proration_at } + : {}), + ...(returnUrl === undefined ? {} : { return_url: returnUrl }) + } + } + + async function pay(confirmationToken?: string) { + const arrival = entry.value + const quoted = preview.value + if (arrival?.plan === undefined || !quoted || !canPay.value) return + await checkout.subscribe( + subscribeRequest(arrival, arrival.plan, quoted, confirmationToken) + ) + } + + return { + page: shallowReadonly(page), + preview, + canPay, + submitting: checkout.submitting, + payFailure, + returnLink, + onPaymentPhase, + retryElement: () => dispatch({ type: 'elementRetried' }), + pay + } +} diff --git a/apps/billing-web/src/locales/en/main.json b/apps/billing-web/src/locales/en/main.json index 028a79de18f..fa416f09964 100644 --- a/apps/billing-web/src/locales/en/main.json +++ b/apps/billing-web/src/locales/en/main.json @@ -161,7 +161,34 @@ "promoApplied": "{code} applied.", "promoRenews": "Renews at {amount} on {date}" }, - "error": "Error" + "error": "Error", + "totalDueToday": "Total due today", + "paymentMethod": "Payment method", + "payAndSubscribe": "Pay and subscribe", + "methodChoice": "Choose how you would like to pay.", + "billingAddress": "Billing address", + "alipayRenewalNote": "Alipay renews this plan automatically each period until you cancel.", + "unavailable": "The payment form isn't available right now. Please try again later.", + "fullPage": { + "logo": "Comfy", + "eyebrow": "Subscribe to {plan} · {workspace}", + "eyebrowPlanOnly": "Subscribe to {plan}", + "planName": "{tier} Plan", + "terms": { + "agreement": "By continuing, you agree to Comfy Org's {terms} and {privacy}, and authorize Comfy Org to charge your payment method each billing period until you cancel.", + "terms": "Terms", + "privacyPolicy": "Privacy Policy" + }, + "formFailed": { + "title": "The payment form couldn't load", + "body": "Nothing has been charged. Check your connection and try again — your order details are unaffected.", + "retry": "Try again" + }, + "refused": { + "title": "You can't subscribe from this account", + "body": "This account can't start or change a subscription for this workspace. Ask the workspace owner, or go back and choose another workspace." + } + } }, "hosted": { "loading": "Loading…", diff --git a/apps/billing-web/src/views/FullPageCheckoutView.test.ts b/apps/billing-web/src/views/FullPageCheckoutView.test.ts new file mode 100644 index 00000000000..814e0a986c8 --- /dev/null +++ b/apps/billing-web/src/views/FullPageCheckoutView.test.ts @@ -0,0 +1,331 @@ +import userEvent from '@testing-library/user-event' +import { render, screen, waitFor } from '@testing-library/vue' +import { nextTick, ref } from 'vue' + +import type { PreviewSubscribeResult } from '@comfyorg/account-core/billing' +import type { AccountCredential } from '@comfyorg/account-core/session' +import { BILLING_CLIENT_KEY } from '@comfyorg/account-ui/billing' +import type { StripePaymentPhase } from '@comfyorg/account-ui/billing/stripe' +import { parseBillingEntry } from '@comfyorg/billing-contract' + +import { recordBillingEntry } from '@/entry/billingEntry' +import { createBillingI18n } from '@/i18n' +import type { + FakeBillingClient, + FakeBillingClientOptions +} from '@/test/fakeBillingClient' +import { + createFakeBillingClient, + pendingOperation, + previewOf +} from '@/test/fakeBillingClient' +import FullPageCheckoutView from '@/views/FullPageCheckoutView.vue' + +const CHECKOUT_PATH = + '/v1/checkout?product=comfyui&return_to=comfyui_workspace&plan=creator_monthly' + +vi.mock(import('@/config/env'), () => ({ + BILLING_WEB_ENV: 'test', + CLOUD_BASE_URL: 'https://testcloud.comfy.org' +})) + +vi.mock(import('@/config/stripeKey'), () => ({ + awaitBillingWebStripeKey: () => Promise.resolve('pk_test_example'), + useBillingWebStripeKey: () => ref('pk_test_example') +})) + +vi.mock(import('@/session/stripeChallengePort'), () => ({ + createDeferredStripeChallengePort: () => ({ + handleNextAction: async () => ({}) + }) +})) + +vi.mock(import('@/entry/workspaceBinding'), () => ({ + boundWorkspaceId: () => undefined, + bindEntryWorkspace: () => false +})) + +const SESSION: AccountCredential = { + token: 'jwt-1', + permissions: [], + expiresAt: Date.now() + 3_600_000, + uid: 'uid-1', + workspace: { id: 'ws-team', name: 'Acme Team', type: 'team' }, + role: 'owner' +} + +vi.mock(import('@/session/billingWebSession'), async () => { + const { computed } = await import('vue') + return { + useBillingWebSession: () => ({ + phase: computed(() => 'authenticated' as const), + user: computed(() => null), + session: computed(() => SESSION), + failure: computed(() => undefined) + }) + } +}) + +/** The provider form is covered in its package; here it reports phases and hands back a token. */ +const form = vi.hoisted(() => ({ + mounts: 0, + emit: (() => {}) as (event: string, payload: unknown) => void +})) + +vi.mock(import('@comfyorg/account-ui/billing/stripe'), () => ({ + StripePaymentForm: { + name: 'StripePaymentForm', + props: { + canSubmit: { type: Boolean, default: true }, + isLoading: { type: Boolean, default: false } + }, + emits: ['confirm', 'phase'], + setup( + props: { canSubmit: boolean; isLoading: boolean }, + { + emit, + slots + }: { + emit: (event: string, payload: unknown) => void + slots: { submit?: (slotProps: Record) => unknown } + } + ) { + form.mounts += 1 + form.emit = emit + return () => + slots.submit?.({ disabled: !props.canSubmit, loading: props.isLoading }) + } + } +})) + +function reportPhase(phase: StripePaymentPhase) { + form.emit('phase', phase) +} + +async function renderCheckout( + options: FakeBillingClientOptions = {}, + arrange: (fake: FakeBillingClient) => void = () => {} +) { + recordBillingEntry(parseBillingEntry(CHECKOUT_PATH)) + const fake = createFakeBillingClient({ + preview: { status: 'ok', value: previewOf({ quote_id: 'q_1' }) }, + capabilities: { can_subscribe_self_serve: true }, + ...options + }) + arrange(fake) + render(FullPageCheckoutView, { + global: { + plugins: [createBillingI18n()], + provide: { [BILLING_CLIENT_KEY]: fake.client } + } + }) + return fake +} + +const payButton = () => + screen.getByRole('button', { name: 'Pay and subscribe' }) + +describe('FullPageCheckoutView', () => { + beforeEach(() => { + form.mounts = 0 + }) + + it('holds the skeleton with Pay disabled until the quote and the element are both ready', async () => { + let answerQuote: (result: PreviewSubscribeResult) => void = () => {} + await renderCheckout({}, (fake) => + fake.previewSubscribe.mockImplementation( + () => new Promise((resolve) => (answerQuote = resolve)) + ) + ) + + expect(screen.getByText('Loading…')).toBeInTheDocument() + expect(screen.getByText('Total due today')).toBeInTheDocument() + expect(payButton()).toBeDisabled() + expect(form.mounts).toBe(0) + + answerQuote({ status: 'ok', value: previewOf() }) + + expect( + await screen.findByText('Subscribe to Creator Plan · Acme Team') + ).toBeInTheDocument() + expect(screen.getAllByText('$28.00')).toHaveLength(2) + expect(screen.queryByText('Loading…')).not.toBeInTheDocument() + expect(payButton()).toBeDisabled() + + reportPhase({ phase: 'payment_element_ready', element: 'address' }) + await nextTick() + expect(payButton()).toBeDisabled() + + reportPhase({ phase: 'payment_element_ready', element: 'payment' }) + await waitFor(() => expect(payButton()).toBeEnabled()) + }) + + it('subscribes with the quoted plan and the confirmation token on Pay', async () => { + const fake = await renderCheckout() + await screen.findByText('Subscribe to Creator Plan · Acme Team') + reportPhase({ phase: 'payment_element_ready', element: 'payment' }) + + form.emit('confirm', 'ctoken_1') + + await waitFor(() => + expect(fake.subscribe).toHaveBeenCalledWith( + expect.objectContaining({ + plan_slug: 'creator_monthly', + confirmation_token: 'ctoken_1', + quote_id: 'q_1' + }) + ) + ) + }) + + it('charges a plan change to the method on file without mounting the card form', async () => { + const fake = await renderCheckout({ + preview: { + status: 'ok', + value: previewOf({ transition_type: 'upgrade' }) + } + }) + await screen.findByText('Subscribe to Creator Plan · Acme Team') + + expect(form.mounts).toBe(0) + await userEvent.click(payButton()) + + await waitFor(() => expect(fake.subscribe).toHaveBeenCalledOnce()) + expect(fake.subscribe.mock.calls[0][0]).not.toHaveProperty( + 'confirmation_token' + ) + }) + + it.for>([ + { + phase: 'payment_element_failed', + element: 'payment', + element_phase: 'init' + }, + { + phase: 'payment_element_failed', + element: 'payment', + element_phase: 'mount' + }, + { + phase: 'payment_element_failed', + element: 'address', + element_phase: 'mount' + }, + { + phase: 'payment_element_failed', + element: 'payment', + element_phase: 'update' + } + ])( + 'replaces the whole payment column when the $element element fails at $element_phase, and Try again remounts it', + async (failure) => { + await renderCheckout() + await screen.findByText('Subscribe to Creator Plan · Acme Team') + reportPhase(failure) + + expect( + await screen.findByText("The payment form couldn't load") + ).toBeInTheDocument() + expect( + screen.queryByRole('button', { name: 'Pay and subscribe' }) + ).not.toBeInTheDocument() + expect( + screen.getByText('Subscribe to Creator Plan · Acme Team') + ).toBeInTheDocument() + + await userEvent.click(screen.getByRole('button', { name: 'Try again' })) + + expect(form.mounts).toBe(2) + expect( + screen.queryByText("The payment form couldn't load") + ).not.toBeInTheDocument() + expect(payButton()).toBeDisabled() + } + ) + + it('ignores a confirm that arrives before the element is ready', async () => { + const fake = await renderCheckout() + await screen.findByText('Subscribe to Creator Plan · Acme Team') + + form.emit('confirm', 'ctoken_early') + await nextTick() + + expect(fake.subscribe).not.toHaveBeenCalled() + }) + + it('keeps Pay disabled for a quote the server does not allow', async () => { + await renderCheckout({ + preview: { status: 'ok', value: previewOf({ allowed: false }) } + }) + await screen.findByText('Subscribe to Creator Plan · Acme Team') + reportPhase({ phase: 'payment_element_ready', element: 'payment' }) + await nextTick() + + expect(payButton()).toBeDisabled() + }) + + it('locks Pay once an operation is in flight, so a second click cannot charge twice', async () => { + const fake = await renderCheckout({ + preview: { + status: 'ok', + value: previewOf({ transition_type: 'upgrade' }) + } + }) + await screen.findByText('Subscribe to Creator Plan · Acme Team') + expect(payButton()).toBeEnabled() + + fake.publishOperation(pendingOperation()) + + await waitFor(() => expect(payButton()).toBeDisabled()) + }) + + it.for<{ + name: string + options: FakeBillingClientOptions + arrange: (fake: FakeBillingClient) => void + }>([ + { + name: 'the capabilities read', + options: {}, + arrange: (fake) => + fake.readCapabilities.mockResolvedValue({ + status: 'error', + code: 'REQUEST_FAILED' + }) + }, + { + name: 'the quote', + options: { preview: { status: 'error', code: 'REQUEST_FAILED' } }, + arrange: () => {} + } + ])( + 'says so instead of capture when $name fails', + async ({ options, arrange }) => { + await renderCheckout(options, arrange) + + expect( + await screen.findByText( + "We couldn't reach the billing service. Please try again." + ) + ).toBeInTheDocument() + expect( + screen.queryByRole('button', { name: 'Pay and subscribe' }) + ).not.toBeInTheDocument() + } + ) + + it('renders the refusal instead of capture when the capability is denied', async () => { + await renderCheckout({ capabilities: {} }) + + expect( + await screen.findByRole('heading', { + name: "You can't subscribe from this account" + }) + ).toBeInTheDocument() + expect( + screen.queryByRole('button', { name: 'Pay and subscribe' }) + ).not.toBeInTheDocument() + expect(form.mounts).toBe(0) + }) +}) diff --git a/apps/billing-web/src/views/FullPageCheckoutView.vue b/apps/billing-web/src/views/FullPageCheckoutView.vue index 5dc18cd4494..16077ae4dfc 100644 --- a/apps/billing-web/src/views/FullPageCheckoutView.vue +++ b/apps/billing-web/src/views/FullPageCheckoutView.vue @@ -1,17 +1,136 @@ From c20abff25397d6b48361fae6a2820989e033489b Mon Sep 17 00:00:00 2001 From: dante01yoon Date: Mon, 28 Sep 2026 13:41:58 -0400 Subject: [PATCH 03/18] test(billing-web): cover the full-page checkout eyebrow, Pay readiness and element retry end to end The fake Stripe now reports element ready, or loaderror for as many payment elements as a spec asks, so the full page can be driven to capture and to the whole-column failure. --- apps/billing-web/e2e/checkout-ui.spec.ts | 5 -- apps/billing-web/e2e/fixtures/stripe.ts | 22 +++++-- .../e2e/full-page-checkout.spec.ts | 62 +++++++++++++++++++ 3 files changed, 79 insertions(+), 10 deletions(-) create mode 100644 apps/billing-web/e2e/full-page-checkout.spec.ts diff --git a/apps/billing-web/e2e/checkout-ui.spec.ts b/apps/billing-web/e2e/checkout-ui.spec.ts index 0a6c47e28f0..a42b3ecf0ed 100644 --- a/apps/billing-web/e2e/checkout-ui.spec.ts +++ b/apps/billing-web/e2e/checkout-ui.spec.ts @@ -38,11 +38,6 @@ test('with the flag on full_page, checkout is the full-page checkout', async ({ request.authorization === 'Bearer e2e-workspace-jwt' ) ).toBe(true) - expect( - cloud.requests.some( - (request) => request.path === '/billing/preview-subscribe' - ) - ).toBe(false) }) test('when the flag read fails, checkout falls back to the embedded checkout', async ({ diff --git a/apps/billing-web/e2e/fixtures/stripe.ts b/apps/billing-web/e2e/fixtures/stripe.ts index 9eda912ce6d..3b2a0279f1d 100644 --- a/apps/billing-web/e2e/fixtures/stripe.ts +++ b/apps/billing-web/e2e/fixtures/stripe.ts @@ -2,8 +2,8 @@ * A fake `js.stripe.com` at the network boundary: enough of `window.Stripe` * for `StripePaymentForm` and the embedded-challenge port to run their real * code against, without a request ever reaching Stripe. Elements are inert - * (`mount`/`on`/`destroy` no-ops); `createConfirmationToken` and - * `handleNextAction` always succeed, which is all the current specs need — + * apart from reporting `ready` on the next task; `createConfirmationToken` + * and `handleNextAction` always succeed, which is all the current specs need — * a decline or a timeout is modelled on the mocked Cloud's operation, not * on the payment provider. * @@ -22,12 +22,24 @@ const FAKE_STRIPE_JS = ` // can tell "called correctly" from "called with the wrong secret". nextActionCalls: [] } - function fakeElement() { - return { mount() {}, unmount() {}, destroy() {}, on() {} } + // A spec sets window.__e2eStripeLoadErrors before load to make that many + // payment elements report loaderror instead of ready. + function fakeElement(kind) { + const failing = kind === 'payment' && (window.__e2eStripeLoadErrors ?? 0) > 0 + if (failing) window.__e2eStripeLoadErrors -= 1 + return { + mount() {}, + unmount() {}, + destroy() {}, + on(event, handler) { + if (event === (failing ? 'loaderror' : 'ready')) + setTimeout(() => handler({ error: { code: 'e2e_load_error' } })) + } + } } function fakeElements() { return { - create: () => fakeElement(), + create: (kind) => fakeElement(kind), update: () => Promise.resolve(), submit: () => Promise.resolve({}) } diff --git a/apps/billing-web/e2e/full-page-checkout.spec.ts b/apps/billing-web/e2e/full-page-checkout.spec.ts new file mode 100644 index 00000000000..2f68309b58e --- /dev/null +++ b/apps/billing-web/e2e/full-page-checkout.spec.ts @@ -0,0 +1,62 @@ +import { installFakeStripe } from './fixtures/stripe' +import { entryPath, expect, test as base } from './fixtures/test' + +const test = base.extend<{ fullPage: void }>({ + fullPage: [ + async ({ context, cloud }, use) => { + await installFakeStripe(context) + cloud.scenario.checkoutUi = 'full_page' + cloud.scenario.preview = { + ...cloud.scenario.preview, + payment_method_configuration_id: 'pmc_e2e' + } + await use(undefined) + }, + { auto: true } + ] +}) + +const CHECKOUT = entryPath('checkout', { plan: 'pro_monthly' }) +const EYEBROW = 'Subscribe to Pro Plan · Personal' + +test('names the plan and the workspace, and enables Pay once the form is ready', async ({ + page, + cloud, + signIn +}) => { + await signIn(CHECKOUT) + + await expect(page.getByText(EYEBROW)).toBeVisible() + await expect( + page.getByRole('button', { name: 'Pay and subscribe' }) + ).toBeEnabled() + await expect( + page.getByRole('heading', { name: 'Confirm your payment' }) + ).toBeHidden() + expect( + cloud.requests.some((request) => request.path === '/billing/capabilities') + ).toBe(true) +}) + +test('a payment form that fails to load is replaced, and Try again remounts it', async ({ + page, + signIn +}) => { + await page.addInitScript(() => { + Object.assign(window, { __e2eStripeLoadErrors: 1 }) + }) + await signIn(CHECKOUT) + + await expect(page.getByText("The payment form couldn't load")).toBeVisible() + await expect( + page.getByRole('button', { name: 'Pay and subscribe' }) + ).toBeHidden() + await expect(page.getByText(EYEBROW)).toBeVisible() + + await page.getByRole('button', { name: 'Try again' }).click() + + await expect( + page.getByRole('button', { name: 'Pay and subscribe' }) + ).toBeEnabled() + await expect(page.getByText("The payment form couldn't load")).toBeHidden() +}) From 18303c9da27c6f64e5eb893988593297df6f119b Mon Sep 17 00:00:00 2001 From: dante01yoon Date: Mon, 28 Sep 2026 22:21:04 -0400 Subject: [PATCH 04/18] refactor(billing-web): extract the full-page checkout's subscribe request builder useFullPageCheckout.ts assembled the subscribe request and the result-return URL inline. Move both into apps/billing-web/src/checkout/subscribeRequest.ts as pure functions with a table test. --- .../src/checkout/subscribeRequest.test.ts | 163 ++++++++++++++++++ .../src/checkout/subscribeRequest.ts | 65 +++++++ .../src/composables/useFullPageCheckout.ts | 69 ++------ 3 files changed, 245 insertions(+), 52 deletions(-) create mode 100644 apps/billing-web/src/checkout/subscribeRequest.test.ts create mode 100644 apps/billing-web/src/checkout/subscribeRequest.ts diff --git a/apps/billing-web/src/checkout/subscribeRequest.test.ts b/apps/billing-web/src/checkout/subscribeRequest.test.ts new file mode 100644 index 00000000000..a84edc3d959 --- /dev/null +++ b/apps/billing-web/src/checkout/subscribeRequest.test.ts @@ -0,0 +1,163 @@ +import type { + SubscribeInput, + SubscriptionPreview +} from '@comfyorg/account-core/billing' +import type { BillingEntry } from '@comfyorg/billing-contract' +import { parseBillingEntry } from '@comfyorg/billing-contract' + +import { buildSubscribeRequest } from '@/checkout/subscribeRequest' +import { previewOf } from '@/test/fakeBillingClient' + +function entryOf(query: string): BillingEntry { + const result = parseBillingEntry(`https://billing.test/v1/checkout?${query}`) + if (result.status !== 'ok') throw new Error('bad fixture entry') + return result.entry +} + +const arrival = entryOf( + 'product=comfyui&return_to=comfyui_workspace&plan=creator_monthly' +) +const teamArrival = entryOf( + 'product=comfyui&return_to=comfyui_workspace&plan=team_per_credit_annual&team_credit_stop_id=stop_700' +) + +describe('buildSubscribeRequest', () => { + it.for<{ + name: string + arrival: BillingEntry + plan: string + quoted: SubscriptionPreview + confirmationToken: string | undefined + confirmReactivation: boolean + returnUrl: string | undefined + expected: SubscribeInput + }>([ + { + name: 'a new subscription with the payment token', + arrival, + plan: 'creator_monthly', + quoted: previewOf({ quote_id: 'q_1', quote_version: 3 }), + confirmationToken: 'ctoken_1', + confirmReactivation: false, + returnUrl: 'https://billing.test/v1/result', + expected: { + plan_slug: 'creator_monthly', + confirmation_token: 'ctoken_1', + quote_id: 'q_1', + quote_version: 3, + return_url: 'https://billing.test/v1/result' + } + }, + { + name: 'a plan change against the saved method, no token', + arrival, + plan: 'creator_annual', + quoted: previewOf({ + transition_type: 'upgrade', + quote_id: 'q_2', + quote_version: 7 + }), + confirmationToken: undefined, + confirmReactivation: false, + returnUrl: 'https://billing.test/v1/result', + expected: { + plan_slug: 'creator_annual', + quote_id: 'q_2', + quote_version: 7, + return_url: 'https://billing.test/v1/result' + } + }, + { + name: 'an immediate change, priced at the quoted instant', + arrival, + plan: 'creator_monthly', + quoted: previewOf({ + is_immediate: true, + proration_at: '2026-09-18T12:00:00.000Z' + }), + confirmationToken: 'ctoken_1', + confirmReactivation: false, + returnUrl: undefined, + expected: { + plan_slug: 'creator_monthly', + confirmation_token: 'ctoken_1', + proration_at: '2026-09-18T12:00:00.000Z' + } + }, + { + name: 'a change that takes effect later, left unpriced', + arrival, + plan: 'creator_monthly', + quoted: previewOf({ + is_immediate: false, + proration_at: '2026-09-18T12:00:00.000Z' + }), + confirmationToken: 'ctoken_1', + confirmReactivation: false, + returnUrl: undefined, + expected: { + plan_slug: 'creator_monthly', + confirmation_token: 'ctoken_1' + } + }, + { + name: "a team plan naming its arrival's credit stop", + arrival: teamArrival, + plan: 'team_per_credit_annual', + quoted: previewOf(), + confirmationToken: undefined, + confirmReactivation: false, + returnUrl: undefined, + expected: { + plan_slug: 'team_per_credit_annual', + team_credit_stop_id: 'stop_700' + } + }, + { + name: 'a confirmed reactivation charge', + arrival, + plan: 'creator_monthly', + quoted: previewOf({ requires_reactivation_confirmation: true }), + confirmationToken: 'ctoken_1', + confirmReactivation: true, + returnUrl: undefined, + expected: { + plan_slug: 'creator_monthly', + confirmation_token: 'ctoken_1', + confirm_reactivation: true + } + }, + { + name: 'a missing return url, left out of the request', + arrival, + plan: 'creator_monthly', + quoted: previewOf(), + confirmationToken: undefined, + confirmReactivation: false, + returnUrl: undefined, + expected: { plan_slug: 'creator_monthly' } + } + ])( + '$name', + ({ + arrival, + plan, + quoted, + confirmationToken, + confirmReactivation, + returnUrl, + expected + }) => { + expect( + buildSubscribeRequest({ + arrival, + plan, + quoted, + confirmationToken, + confirmReactivation, + returnUrl + }) + ).toEqual(expected) + } + ) +}) diff --git a/apps/billing-web/src/checkout/subscribeRequest.ts b/apps/billing-web/src/checkout/subscribeRequest.ts new file mode 100644 index 00000000000..998309f905f --- /dev/null +++ b/apps/billing-web/src/checkout/subscribeRequest.ts @@ -0,0 +1,65 @@ +/** + * The full-page checkout's subscribe request: where a hosted continuation + * sends the customer back, and the body `checkout.subscribe` posts. + */ +import type { + SubscribeInput, + SubscriptionPreview +} from '@comfyorg/account-core/billing' +import type { BillingEntry } from '@comfyorg/billing-contract' +import { buildBillingEntryUrl } from '@comfyorg/billing-contract' + +/** Where a hosted payment step sends the customer back: this origin, same request. */ +export function checkoutResultUrl( + arrival: BillingEntry, + workspaceId: string | undefined, + billingOrigin: string +): string | undefined { + const built = buildBillingEntryUrl({ + billingOrigin, + intent: 'result', + product: arrival.product, + returnTo: arrival.returnTo, + ...(arrival.plan === undefined ? {} : { plan: arrival.plan }), + ...(arrival.teamCreditStopId === undefined + ? {} + : { teamCreditStopId: arrival.teamCreditStopId }), + ...(workspaceId === undefined ? {} : { workspaceId }) + }) + return built.status === 'ok' ? built.url.href : undefined +} + +export function buildSubscribeRequest({ + arrival, + plan, + quoted, + confirmationToken, + confirmReactivation, + returnUrl +}: { + arrival: BillingEntry + plan: string + quoted: SubscriptionPreview + confirmationToken: string | undefined + confirmReactivation: boolean + returnUrl: string | undefined +}): SubscribeInput { + return { + plan_slug: plan, + ...(confirmationToken === undefined + ? {} + : { confirmation_token: confirmationToken }), + ...(arrival.teamCreditStopId === undefined + ? {} + : { team_credit_stop_id: arrival.teamCreditStopId }), + ...(quoted.quote_id === undefined ? {} : { quote_id: quoted.quote_id }), + ...(quoted.quote_version === undefined + ? {} + : { quote_version: quoted.quote_version }), + ...(quoted.is_immediate && quoted.proration_at !== undefined + ? { proration_at: quoted.proration_at } + : {}), + ...(returnUrl === undefined ? {} : { return_url: returnUrl }), + ...(confirmReactivation ? { confirm_reactivation: true } : {}) + } +} diff --git a/apps/billing-web/src/composables/useFullPageCheckout.ts b/apps/billing-web/src/composables/useFullPageCheckout.ts index 2ff1c773f3e..ed6cd0a8605 100644 --- a/apps/billing-web/src/composables/useFullPageCheckout.ts +++ b/apps/billing-web/src/composables/useFullPageCheckout.ts @@ -1,9 +1,5 @@ import { computed, shallowReadonly, shallowRef } from 'vue' -import type { - SubscribeInput, - SubscriptionPreview -} from '@comfyorg/account-core/billing' import { useBillingClient, useCheckout, @@ -11,10 +7,7 @@ import { } from '@comfyorg/account-ui/billing' import type { StripePaymentPhase } from '@comfyorg/account-ui/billing/stripe' import type { BillingEntry } from '@comfyorg/billing-contract' -import { - buildBillingEntryUrl, - buildReturnUrl -} from '@comfyorg/billing-contract' +import { buildReturnUrl } from '@comfyorg/billing-contract' import type { CheckoutPage, CheckoutPageEvent } from '@/checkout/checkoutPage' import { @@ -22,6 +15,10 @@ import { railAcceptsPay, reduceCheckoutPage } from '@/checkout/checkoutPage' +import { + buildSubscribeRequest, + checkoutResultUrl +} from '@/checkout/subscribeRequest' import { useBilledWorkspace } from '@/composables/useBilledWorkspace' import { BILLING_WEB_ENV } from '@/config/env' import { awaitBillingWebStripeKey } from '@/config/stripeKey' @@ -117,55 +114,23 @@ export function useFullPageCheckout() { })?.href }) - /** Where a hosted payment step sends the customer back: this origin, same request. */ - function resultUrl(arrival: BillingEntry): string | undefined { - const workspaceId = billedWorkspace() - const built = buildBillingEntryUrl({ - billingOrigin: window.location.origin, - intent: 'result', - product: arrival.product, - returnTo: arrival.returnTo, - ...(arrival.plan === undefined ? {} : { plan: arrival.plan }), - ...(arrival.teamCreditStopId === undefined - ? {} - : { teamCreditStopId: arrival.teamCreditStopId }), - ...(workspaceId === undefined ? {} : { workspaceId }) - }) - return built.status === 'ok' ? built.url.href : undefined - } - - function subscribeRequest( - arrival: BillingEntry, - plan: string, - quoted: SubscriptionPreview, - confirmationToken: string | undefined - ): SubscribeInput { - const returnUrl = resultUrl(arrival) - return { - plan_slug: plan, - ...(confirmationToken === undefined - ? {} - : { confirmation_token: confirmationToken }), - ...(arrival.teamCreditStopId === undefined - ? {} - : { team_credit_stop_id: arrival.teamCreditStopId }), - ...(quoted.quote_id === undefined ? {} : { quote_id: quoted.quote_id }), - ...(quoted.quote_version === undefined - ? {} - : { quote_version: quoted.quote_version }), - ...(quoted.is_immediate && quoted.proration_at !== undefined - ? { proration_at: quoted.proration_at } - : {}), - ...(returnUrl === undefined ? {} : { return_url: returnUrl }) - } - } - async function pay(confirmationToken?: string) { const arrival = entry.value const quoted = preview.value if (arrival?.plan === undefined || !quoted || !canPay.value) return await checkout.subscribe( - subscribeRequest(arrival, arrival.plan, quoted, confirmationToken) + buildSubscribeRequest({ + arrival, + plan: arrival.plan, + quoted, + confirmationToken, + confirmReactivation: false, + returnUrl: checkoutResultUrl( + arrival, + billedWorkspace(), + window.location.origin + ) + }) ) } From 7a41f162d3d243a9f1ed8cfd6e2f444271e500d7 Mon Sep 17 00:00:00 2001 From: dante01yoon Date: Mon, 28 Sep 2026 19:14:12 -0400 Subject: [PATCH 05/18] feat(billing-web): fall back to Plan & Credits settings when the checkout link has no return destination --- .../src/checkout/cloudLinks.test.ts | 22 +++++++++++++ apps/billing-web/src/checkout/cloudLinks.ts | 28 ++++++++++++++++ .../fullPage/CheckoutSummaryColumn.vue | 4 +-- .../src/composables/useFullPageCheckout.ts | 17 ++++++---- .../src/views/FullPageCheckoutView.test.ts | 32 +++++++++++++++++-- .../src/views/FullPageCheckoutView.vue | 9 ++---- 6 files changed, 94 insertions(+), 18 deletions(-) create mode 100644 apps/billing-web/src/checkout/cloudLinks.test.ts create mode 100644 apps/billing-web/src/checkout/cloudLinks.ts diff --git a/apps/billing-web/src/checkout/cloudLinks.test.ts b/apps/billing-web/src/checkout/cloudLinks.test.ts new file mode 100644 index 00000000000..19615eed5a1 --- /dev/null +++ b/apps/billing-web/src/checkout/cloudLinks.test.ts @@ -0,0 +1,22 @@ +import { planCreditsSettingsUrl } from '@/checkout/cloudLinks' + +vi.mock(import('@/config/env'), () => ({ + CLOUD_BASE_URL: 'https://testcloud.comfy.org' +})) + +describe('planCreditsSettingsUrl', () => { + it.for<{ name: string; workspace: string | undefined; href: string }>([ + { + name: 'opens the panel in the billed workspace', + workspace: 'ws_1', + href: 'https://testcloud.comfy.org/?settings=plan-credits&workspace=ws_1' + }, + { + name: 'names no workspace when none is bound', + workspace: undefined, + href: 'https://testcloud.comfy.org/?settings=plan-credits' + } + ])('$name', ({ workspace, href }) => { + expect(planCreditsSettingsUrl(workspace)).toBe(href) + }) +}) diff --git a/apps/billing-web/src/checkout/cloudLinks.ts b/apps/billing-web/src/checkout/cloudLinks.ts new file mode 100644 index 00000000000..6d66d37e423 --- /dev/null +++ b/apps/billing-web/src/checkout/cloudLinks.ts @@ -0,0 +1,28 @@ +/** + * Deep links into the cloud app, the one host every checkout can fall back + * to. Each opens in the workspace billing acted on, as a return URL does, so + * the host lands on that workspace rather than its last-used one. + */ +import { CLOUD_BASE_URL } from '@/config/env' + +/** What a return URL names the billed workspace under; see `buildReturnUrl`. */ +const WORKSPACE_PARAM = 'workspace' + +function cloudDeepLink( + params: Readonly>, + workspaceId: string | undefined +): string { + const url = new URL('/', CLOUD_BASE_URL) + for (const [name, value] of Object.entries(params)) + url.searchParams.set(name, value) + if (workspaceId !== undefined) + url.searchParams.set(WORKSPACE_PARAM, workspaceId) + return url.href +} + +/** The Plan & Credits settings panel: where checkout returns when the link named nowhere to go back to. */ +export function planCreditsSettingsUrl( + workspaceId: string | undefined +): string { + return cloudDeepLink({ settings: 'plan-credits' }, workspaceId) +} diff --git a/apps/billing-web/src/components/fullPage/CheckoutSummaryColumn.vue b/apps/billing-web/src/components/fullPage/CheckoutSummaryColumn.vue index cf65a72dd8d..a58c8fc05eb 100644 --- a/apps/billing-web/src/components/fullPage/CheckoutSummaryColumn.vue +++ b/apps/billing-web/src/components/fullPage/CheckoutSummaryColumn.vue @@ -10,9 +10,8 @@ export interface CheckoutSummary { readonly total: string } -const { summary, canGoBack } = defineProps<{ +const { summary } = defineProps<{ summary?: CheckoutSummary - canGoBack: boolean }>() const emit = defineEmits<{ back: [] }>() @@ -31,7 +30,6 @@ const SKELETON_BAR =