Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion apps/billing-web/e2e/full-page-endings.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ test('643-14654: a change already scheduled is named from the server, and withou
await expect(heading(page, 'Checkout not available')).toBeVisible()
await expect(
page.getByText(
'Your plan is set to change to Pro · Monthly on October 28, 2026. Cancel that change in your billing settings to make a different one.'
'Your plan is set to change to Pro on October 28, 2026. Cancel that change in your billing settings to make a different one.'
)
).toBeVisible()
await expect(code(page)).toHaveText('SUBSCRIPTION_CHANGE_IN_PROGRESS')
Expand Down Expand Up @@ -417,6 +417,11 @@ test("a re-read of the workspace's payments that fails never claims nothing was
await signIn(CHECKOUT)

await expect(heading(page, "Couldn't load your checkout")).toBeVisible()
await expect(
page.getByText(
"We couldn't check your recent payments, so checkout can't open yet. Try again, or contact support if this keeps happening."
)
).toBeVisible()
await expect(page.getByText(/Nothing has been charged/)).toBeHidden()
await expect(payButton(page)).toBeHidden()

Expand Down
18 changes: 13 additions & 5 deletions apps/billing-web/src/checkout/checkoutPage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ describe('reduceCheckoutPage', () => {
{
name: 'a failed read',
events: [unavailable],
expected: { kind: 'unavailable', code: 'REQUEST_FAILED' },
expected: { kind: 'unavailable', cause: 'quote', code: 'REQUEST_FAILED' },
pay: false
},
{
Expand Down Expand Up @@ -571,7 +571,11 @@ describe('reduceCheckoutPage after Pay', () => {
{ type: 'requoteFailed', code: 'REQUEST_FAILED' }
])

expect(page).toEqual({ kind: 'unavailable', code: 'REQUEST_FAILED' })
expect(page).toEqual({
kind: 'unavailable',
cause: 'quote',
code: 'REQUEST_FAILED'
})
expect(railAcceptsPay(page)).toBe(false)
}
)
Expand Down Expand Up @@ -936,9 +940,13 @@ describe('reduceCheckoutPage endings', () => {
expected: RESOLVING
},
{
name: "a re-read of the workspace's payments that fails is its own ending, not a failed load",
name: "a re-read of the workspace's payments that fails is a failed load of the re-read",
events: [recheckFailed],
expected: { kind: 'recheck_failed', code: 'REQUEST_FAILED' }
expected: {
kind: 'unavailable',
cause: 'recheck',
code: 'REQUEST_FAILED'
}
},
{
name: 'Try again after a failed re-read resolves again',
Expand Down Expand Up @@ -1241,7 +1249,7 @@ describe('isLocked', () => {
},
{
name: 'unavailable',
page: { kind: 'unavailable', code: 'REQUEST_FAILED' },
page: { kind: 'unavailable', cause: 'quote', code: 'REQUEST_FAILED' },
locked: false
},
{
Expand Down
36 changes: 20 additions & 16 deletions apps/billing-web/src/checkout/checkoutPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,20 +105,26 @@ type Attribution = 'started' | 'followed' | 'settled'
* settles. `unconfirmed` is money whose outcome the page could not learn, so
* it neither offers a form nor claims a charge. `sibling` on either marks
* money another tab sent while this one had its form open, whose verdict and
* challenge belong to that tab. `recheck_failed` is a re-read of what the
* workspace is waiting on that failed before any form showed, so the page
* cannot say whether money is moving. `terminal` is a payment that went
* through.
* challenge belong to that tab. `unavailable` is a read that failed before
* any form showed: the quote, or the re-read of what the workspace is
* waiting on, after which the page cannot say whether money is moving.
* `terminal` is a payment that went through.
*/
/** Which read failed: the quote, or the re-read of the workspace's payments. */
export type LoadFailure = 'quote' | 'recheck'

export type CheckoutPage =
| { readonly kind: 'resolving'; readonly outcome?: InlineOutcome }
| {
readonly kind: 'refused'
readonly reason: CapabilityDenialReason
readonly scheduled?: ScheduledChange
}
| { readonly kind: 'unavailable'; readonly code: string }
| { readonly kind: 'recheck_failed'; readonly code: string }
| {
readonly kind: 'unavailable'
readonly cause: LoadFailure
readonly code: string
}
| {
readonly kind: 'plan_unavailable'
readonly reason: PlanUnavailableReason
Expand Down Expand Up @@ -297,20 +303,14 @@ function stoppedOn(event: StopEvent): CheckoutPage {
...(event.scheduled === undefined ? {} : { scheduled: event.scheduled })
}
case 'unavailable':
return { kind: 'unavailable', code: event.code }
return { kind: 'unavailable', cause: 'quote', code: event.code }
case 'recheckFailed':
return { kind: 'recheck_failed', code: event.code }
return { kind: 'unavailable', cause: 'recheck', code: event.code }
case 'planUnavailable':
return { kind: 'plan_unavailable', reason: event.reason }
}
}

/** Try again re-reads a checkout whose load or re-read failed. */
const RETRYABLE: ReadonlySet<CheckoutPage['kind']> = new Set([
'unavailable',
'recheck_failed'
])

/** An event that means nothing in the current state returns it untouched. */
export function reduceCheckoutPage(
page: CheckoutPage,
Expand All @@ -325,9 +325,13 @@ export function reduceCheckoutPage(
case 'planUnavailable':
return page.kind === 'resolving' ? stoppedOn(event) : page
case 'requoteFailed':
return leavingCapture(page, { kind: 'unavailable', code: event.code })
return leavingCapture(page, {
kind: 'unavailable',
cause: 'quote',
code: event.code
})
case 'retried':
return RETRYABLE.has(page.kind) ? RESOLVING : page
return page.kind === 'unavailable' ? RESOLVING : page
case 'quoted':
return page.kind === 'resolving' ? arrived(page, event) : page
case 'reconciled':
Expand Down
8 changes: 4 additions & 4 deletions apps/billing-web/src/checkout/endingScreen.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,13 @@ describe('endingOf', () => {
},
{
name: 'a checkout that could not load',
page: { kind: 'unavailable', code: 'REQUEST_FAILED' },
screen: { kind: 'load_failed', code: 'REQUEST_FAILED' }
page: { kind: 'unavailable', cause: 'quote', code: 'REQUEST_FAILED' },
screen: { kind: 'load_failed', cause: 'quote', code: 'REQUEST_FAILED' }
},
{
name: "a re-read of the workspace's payments that failed",
page: { kind: 'recheck_failed', code: 'REQUEST_FAILED' },
screen: { kind: 'recheck_failed', code: 'REQUEST_FAILED' }
page: { kind: 'unavailable', cause: 'recheck', code: 'REQUEST_FAILED' },
screen: { kind: 'load_failed', cause: 'recheck', code: 'REQUEST_FAILED' }
},
{
name: 'a plan the catalog lacks',
Expand Down
12 changes: 7 additions & 5 deletions apps/billing-web/src/checkout/endingScreen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { CapabilityDenialReason } from '@comfyorg/account-core/billing'

import type {
CheckoutPage,
LoadFailure,
PlanUnavailableReason,
ScheduledChange
} from '@/checkout/checkoutPage'
Expand Down Expand Up @@ -61,8 +62,11 @@ export type EndingScreen =
readonly scheduled: ScheduledChange
}
| { readonly kind: 'plan_unavailable'; readonly code: string }
| { readonly kind: 'load_failed'; readonly code: string }
| { readonly kind: 'recheck_failed'; readonly code: string }
| {
readonly kind: 'load_failed'
readonly cause: LoadFailure
readonly code: string
}

export type EndingKind = EndingScreen['kind']

Expand All @@ -72,9 +76,7 @@ export function endingOf(page: CheckoutPage): EndingScreen | undefined {
case 'refused':
return refusedEnding(page)
case 'unavailable':
return { kind: 'load_failed', code: page.code }
case 'recheck_failed':
return { kind: 'recheck_failed', code: page.code }
return { kind: 'load_failed', cause: page.cause, code: page.code }
case 'plan_unavailable':
return {
kind: 'plan_unavailable',
Expand Down
19 changes: 14 additions & 5 deletions apps/billing-web/src/checkout/summaryLedger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ function verbOf(quote: SubscriptionPreview, commitChange: boolean) {
return commitChange ? 'change' : 'upgrade'
}

function planLabeller({ t, tierName }: LedgerContext) {
return (plan: Plan, cadenceShown: boolean) =>
function planLabeller({ t, tierName }: Pick<LedgerContext, 't' | 'tierName'>) {
return (plan: Pick<Plan, 'tier' | 'duration'>, cadenceShown: boolean) =>
cadenceShown
? t(`${S}.planWithCadence`, {
tier: tierName(plan.tier),
Expand Down Expand Up @@ -266,11 +266,20 @@ function scheduledLedger(r: QuoteReading): FamilyLedger {
}
}

/** A plan named in a sentence: "Pro", or "Pro Yearly" when its cadence matters. */
export function namedPlan(
context: Pick<LedgerContext, 't' | 'tierName'>,
plan: Pick<Plan, 'tier' | 'duration'>,
cadenceShown: boolean
): string {
return cadenceShown
? planLabeller(context)(plan, true)
: context.tierName(plan.tier)
}

/** A team plan is one tier at many commitments, so the kept one is named by its rate. */
function keptPlanLine(r: QuoteReading, current: Plan, until: string): string {
const plan = r.cadenceChanges
? r.planLabel(current, true)
: r.tierName(current.tier)
const plan = namedPlan(r, current, r.cadenceChanges)
if (!r.commitChange)
return r.t(`${S}.trailing.keepUntil`, { plan, date: until })
return r.t(`${S}.trailing.keepCommitmentUntil`, {
Expand Down
56 changes: 31 additions & 25 deletions apps/billing-web/src/components/fullPage/CheckoutEnding.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,27 +81,33 @@ describe('CheckoutEnding', () => {
}
)

it('a refusal for a change already scheduled names the plan and the date it takes effect', () => {
const ending = endingOf({
kind: 'refused',
reason: 'subscription_change_in_progress',
scheduled: {
plan: { tier: 'PRO', duration: 'ANNUAL' },
effectiveAt: '2026-10-28T00:00:00.000Z'
}
})
if (ending === undefined) throw new Error('a refusal is an ending')
renderEnding(ending)
it.for([
{ duration: 'MONTHLY', plan: 'Pro' },
{ duration: 'ANNUAL', plan: 'Pro Yearly' }
] as const)(
'a refusal for a change already scheduled to $duration names it $plan and the full date it takes effect',
({ duration, plan }) => {
const ending = endingOf({
kind: 'refused',
reason: 'subscription_change_in_progress',
scheduled: {
plan: { tier: 'PRO', duration },
effectiveAt: '2026-10-28T00:00:00.000Z'
}
})
if (ending === undefined) throw new Error('a refusal is an ending')
renderEnding(ending)

expect(
screen.getByText(
'Your plan is set to change to Pro · Yearly on October 28, 2026. Cancel that change in your billing settings to make a different one.'
expect(
screen.getByText(
`Your plan is set to change to ${plan} on October 28, 2026. Cancel that change in your billing settings to make a different one.`
)
).toBeInTheDocument()
expect(screen.getByTestId('checkout-ending-code')).toHaveTextContent(
'SUBSCRIPTION_CHANGE_IN_PROGRESS'
)
).toBeInTheDocument()
expect(screen.getByTestId('checkout-ending-code')).toHaveTextContent(
'SUBSCRIPTION_CHANGE_IN_PROGRESS'
)
})
}
)

it.for<{
ending: EndingScreen
Expand Down Expand Up @@ -176,7 +182,7 @@ describe('CheckoutEnding', () => {
closeLine: false
},
{
ending: { kind: 'load_failed', code: 'REQUEST_FAILED' },
ending: { kind: 'load_failed', cause: 'quote', code: 'REQUEST_FAILED' },
title: "Couldn't load your checkout",
body: "We couldn't load your quote. Nothing has been charged. Try again, or contact support if this keeps happening.",
codeLabel: 'If this keeps happening, contact support with this code:',
Expand All @@ -185,16 +191,16 @@ describe('CheckoutEnding', () => {
closeLine: false
},
{
ending: { kind: 'recheck_failed', code: 'REQUEST_FAILED' },
ending: { kind: 'load_failed', cause: 'recheck', code: 'REQUEST_FAILED' },
title: "Couldn't load your checkout",
body: "We couldn't check this workspace's payments, so we can't show your checkout yet. Try again, or contact support if this keeps happening.",
body: "We couldn't check your recent payments, so checkout can't open yet. Try again, or contact support if this keeps happening.",
codeLabel: 'If this keeps happening, contact support with this code:',
action: 'Try again',
support: true,
closeLine: false
}
])(
'$ending.kind reads as designed',
'$ending.kind reads as designed: $body',
({ ending, title, body, codeLabel, action, support, closeLine }) => {
renderEnding(ending)

Expand Down Expand Up @@ -234,12 +240,12 @@ describe('CheckoutEnding', () => {
it.for<{ ending: EndingScreen; action: Action; event: string }>([
{ ending: { kind: 'success' }, action: 'Close', event: 'close' },
{
ending: { kind: 'load_failed', code: 'REQUEST_FAILED' },
ending: { kind: 'load_failed', cause: 'quote', code: 'REQUEST_FAILED' },
action: 'Try again',
event: 'retry'
},
{
ending: { kind: 'recheck_failed', code: 'REQUEST_FAILED' },
ending: { kind: 'load_failed', cause: 'recheck', code: 'REQUEST_FAILED' },
action: 'Try again',
event: 'retry'
},
Expand Down
23 changes: 14 additions & 9 deletions apps/billing-web/src/components/fullPage/CheckoutEnding.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { cn } from '@comfyorg/tailwind-utils'
import type { EndingKind, EndingScreen } from '@/checkout/endingScreen'
import { longDate } from '@/checkout/longDate'
import { supportLinkWithCode } from '@/checkout/payVerdict'
import { namedPlan } from '@/checkout/summaryLedger'
import EndingCodeCard from '@/components/fullPage/EndingCodeCard.vue'
import SuccessCloseFooter from '@/components/fullPage/SuccessCloseFooter.vue'
import { useHostedCopy } from '@/composables/useHostedCopy'
Expand Down Expand Up @@ -43,8 +44,7 @@ const ENDINGS: Readonly<
unconfirmed: { tone: 'waiting', support: true },
refused: { tone: 'refused', support: true },
plan_unavailable: { tone: 'refused', primary: 'view_plans', support: true },
load_failed: { tone: 'refused', primary: 'retry', support: true },
recheck_failed: { tone: 'refused', primary: 'retry', support: true }
load_failed: { tone: 'refused', primary: 'retry', support: true }
}

const ICON: Readonly<Record<Tone, string>> = {
Expand All @@ -68,20 +68,25 @@ const {
const emit = defineEmits<{ close: []; retry: []; viewPlans: [] }>()

const { t, locale } = useI18n()
const { planName } = useHostedCopy()
const { coded } = useHostedCopy()

const ending = computed(() => ENDINGS[screen.kind])
const copyKey = computed(() => `checkout.fullPage.ending.${screen.kind}`)
const bodyKey = computed(() =>
screen.kind === 'refused'
? `${copyKey.value}.body.${screen.copy}`
: `${copyKey.value}.body`
)
const bodyKey = computed(() => {
if (screen.kind === 'refused') return `${copyKey.value}.body.${screen.copy}`
if (screen.kind === 'load_failed')
return `${copyKey.value}.body.${screen.cause}`
return `${copyKey.value}.body`
})
const bodyParams = computed(() =>
screen.kind === 'refused' && screen.copy === 'change_scheduled'
? {
workspace,
plan: planName(screen.scheduled.plan),
plan: namedPlan(
{ t, tierName: (tier) => coded('tier', tier) },
screen.scheduled.plan,
screen.scheduled.plan.duration === 'ANNUAL'
),
date: longDate(screen.scheduled.effectiveAt, locale.value)
}
: { workspace }
Expand Down
10 changes: 4 additions & 6 deletions apps/billing-web/src/locales/en/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -326,12 +326,10 @@
},
"load_failed": {
"title": "Couldn't load your checkout",
"body": "We couldn't load your quote. Nothing has been charged. Try again, or contact support if this keeps happening.",
"codeLabel": "If this keeps happening, contact support with this code:"
},
"recheck_failed": {
"title": "Couldn't load your checkout",
"body": "We couldn't check this workspace's payments, so we can't show your checkout yet. Try again, or contact support if this keeps happening.",
"body": {
"quote": "We couldn't load your quote. Nothing has been charged. Try again, or contact support if this keeps happening.",
"recheck": "We couldn't check your recent payments, so checkout can't open yet. Try again, or contact support if this keeps happening."
},
"codeLabel": "If this keeps happening, contact support with this code:"
}
},
Expand Down
Loading
Loading