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
2 changes: 1 addition & 1 deletion .github/workflows/ci-oss-assets-validation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ jobs:
if pnpx license-checker-rseidelsohn@4 \
--production \
--summary \
--excludePackages '@comfyorg/comfyui-frontend;@comfyorg/account;@comfyorg/account-ui;@comfyorg/design-system;@comfyorg/ingest-types;@comfyorg/registry-types;@comfyorg/shared-frontend-utils;@comfyorg/tailwind-utils;@comfyorg/comfyui-electron-types;@comfyorg/comfy-multi-player' \
--excludePackages '@comfyorg/comfyui-frontend;@comfyorg/account;@comfyorg/account-ui;@comfyorg/billing-contract;@comfyorg/design-system;@comfyorg/ingest-types;@comfyorg/registry-types;@comfyorg/shared-frontend-utils;@comfyorg/tailwind-utils;@comfyorg/comfyui-electron-types;@comfyorg/comfy-multi-player' \
--clarificationsFile .github/license-clarifications.json \
--onlyAllow 'MIT;MIT*;Apache-2.0;BSD-2-Clause;BSD-3-Clause;ISC;0BSD;BlueOak-1.0.0;Python-2.0;CC0-1.0;Unlicense;(MIT OR Apache-2.0);(MIT OR GPL-3.0);(Apache-2.0 OR MIT);(MPL-2.0 OR Apache-2.0);MPL-2.0;CC-BY-4.0;CC-BY-3.0;GPL-3.0-only'; then
echo ''
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ci-tests-unit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
- name: Run package unit tests with coverage
run: |
rc=0
for pkg in account account-ui object-info-parser shared-frontend-utils design-system; do
for pkg in account account-ui billing-contract object-info-parser shared-frontend-utils design-system; do
pnpm --filter "@comfyorg/$pkg" exec vitest run --coverage || rc=1
done
exit $rc
Expand All @@ -60,7 +60,7 @@ jobs:
if: always()
uses: codecov/codecov-action@fb8b3582c8e4def4969c97caa2f19720cb33a72f # v7.0.0
with:
files: coverage/lcov.info,packages/account/coverage/lcov.info,packages/account-ui/coverage/lcov.info,packages/object-info-parser/coverage/lcov.info,packages/shared-frontend-utils/coverage/lcov.info,packages/design-system/coverage/lcov.info
files: coverage/lcov.info,packages/account/coverage/lcov.info,packages/account-ui/coverage/lcov.info,packages/billing-contract/coverage/lcov.info,packages/object-info-parser/coverage/lcov.info,packages/shared-frontend-utils/coverage/lcov.info,packages/design-system/coverage/lcov.info
flags: unit
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: false
1 change: 1 addition & 0 deletions apps/billing-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"dependencies": {
"@comfyorg/account": "workspace:*",
"@comfyorg/account-ui": "workspace:*",
"@comfyorg/billing-contract": "workspace:*",
"@comfyorg/design-system": "workspace:*",
"@comfyorg/tailwind-utils": "workspace:*",
"@vueuse/core": "catalog:",
Expand Down
20 changes: 0 additions & 20 deletions apps/billing-web/src/App.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,4 @@ describe('billing app', () => {
screen.getByRole('button', { name: 'Pay and subscribe' })
).toBeDisabled()
})

it('recovers unknown static-host paths to the app entry route', async () => {
const router = createBillingRouter(
createMemoryHistory(),
() => 'authenticated'
)

await router.push('/unknown-path')
await router.isReady()

render(App, {
global: {
plugins: [createBillingI18n(), router]
}
})

expect(
await screen.findByRole('heading', { name: 'Confirm your payment' })
).toBeInTheDocument()
})
})
7 changes: 6 additions & 1 deletion apps/billing-web/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
import { computed } from 'vue'

import BillingShell from '@/components/BillingShell.vue'
import { useBillingEntry } from '@/entry/billingEntry'
import { useBillingWebSession } from '@/session/billingWebSession'
import EntryErrorView from '@/views/EntryErrorView.vue'

const { error } = useBillingEntry()
const { session } = useBillingWebSession()

/** A new key is a new scope, so the shell remounts with a fresh client. */
Expand All @@ -15,7 +18,9 @@ const scopeKey = computed(() =>
</script>

<template>
<BillingShell v-if="scopeKey" :key="scopeKey">
<!-- An entry error outranks the session: no account repairs a bad link. -->
<EntryErrorView v-if="error" />
<BillingShell v-else-if="scopeKey" :key="scopeKey">
<RouterView />
</BillingShell>
<RouterView v-else />
Expand Down
49 changes: 49 additions & 0 deletions apps/billing-web/src/components/HostedSurface.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { render, screen } from '@testing-library/vue'

import { parseBillingEntry } from '@comfyorg/billing-contract'

import HostedSurface from '@/components/HostedSurface.vue'
import { recordBillingEntry } from '@/entry/billingEntry'
import { createBillingI18n } from '@/i18n'

function renderSurface() {
return render(HostedSurface, {
slots: { default: '<p>surface content</p>' },
global: { plugins: [createBillingI18n()] }
})
}

describe('HostedSurface', () => {
beforeEach(() => {
recordBillingEntry(
parseBillingEntry(
'/v1/subscription?product=comfyui&return_to=comfyui_credits'
)
)
})

it('shows the surface the intent asked for', () => {
renderSurface()

expect(screen.getByText('surface content')).toBeInTheDocument()
})

it('links back to the product that sent the visitor here', () => {
renderSurface()

expect(
screen.getByRole('link', { name: 'Return to ComfyUI' })
).toHaveAttribute(
'href',
'https://testcloud.comfy.org/?settings=plan-credits'
)
})

it('offers no way back when the arriving link named no destination', () => {
recordBillingEntry(undefined)

renderSurface()

expect(screen.queryByRole('link')).not.toBeInTheDocument()
})
})
66 changes: 66 additions & 0 deletions apps/billing-web/src/components/HostedSurface.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<script setup lang="ts">
import { computed } from 'vue'
import { useI18n } from 'vue-i18n'

import { buildReturnUrl } from '@comfyorg/billing-contract'

import { useHostedCopy } from '@/composables/useHostedCopy'
import { BILLING_WEB_ENV } from '@/config/env'
import { useBillingEntry } from '@/entry/billingEntry'

const { t } = useI18n()
const { coded } = useHostedCopy()
const { entry, error } = useBillingEntry()

const title = computed(() => coded('title', entry.value?.intent))

const returnLink = computed(() => {
const arrival = entry.value
if (!arrival) return undefined
const url = buildReturnUrl({
target: arrival.returnTo,
environment: BILLING_WEB_ENV
})
if (!url) return undefined
return {
href: url.href,
label: t('hosted.returnTo', {
product: coded('product', arrival.product)
})
}
})
</script>

<template>
<main
class="dark-theme fixed inset-0 overflow-auto bg-charcoal-950 px-4 py-6 font-inter sm:px-6 sm:py-10"
>
<div class="mx-auto flex max-w-3xl flex-col gap-6">
<header class="flex flex-wrap items-center justify-between gap-3">
<h1 class="m-0 text-xl font-semibold text-base-foreground">
{{ title }}
</h1>
<a
v-if="returnLink"
:href="returnLink.href"
class="text-sm text-muted-foreground underline underline-offset-4 hover:text-base-foreground"
>
{{ returnLink.label }}
</a>
</header>

<section
v-if="error"
class="rounded-xl border border-border-subtle bg-secondary-background p-6"
>
<h2 class="m-0 text-base font-semibold text-base-foreground">
{{ t('hosted.entryError.title') }}
</h2>
<p class="mt-2 mb-0 text-sm text-muted-foreground">
{{ coded('entryError', error) }}
</p>
</section>
<slot v-else />
</div>
</main>
</template>
122 changes: 122 additions & 0 deletions apps/billing-web/src/components/PaymentMethodsPanel.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
<script setup lang="ts">
import { computed, ref } from 'vue'
import { useI18n } from 'vue-i18n'
import { useRoute, useRouter } from 'vue-router'

import type { SavedPaymentMethod } from '@comfyorg/account/billing'
import {
usePaymentMethods,
useBillingClient
} from '@comfyorg/account-ui/billing'

import { useHostedCopy } from '@/composables/useHostedCopy'

/** Marks the customer's trip back from the provider's hosted portal. */
const PORTAL_PARAM = 'portal'
const PORTAL_RETURN = 'return'

const { t } = useI18n()
const { coded } = useHostedCopy()
const route = useRoute()
const router = useRouter()
const { commands } = useBillingClient<'commands'>(undefined)

const returningFromPortal = route.query[PORTAL_PARAM] === PORTAL_RETURN

const { methods, defaultMethod, loading, failure, invalidateAndRefresh } =
usePaymentMethods({ immediate: !returningFromPortal })

const portalFailure = ref<string | undefined>()
const openingPortal = ref(false)

const rows = computed(() =>
(methods.value ?? []).map((method) => ({
id: method.id,
label: describe(method),
isDefault: method.id === defaultMethod.value?.id
}))
)

function describe(method: SavedPaymentMethod): string {
if (method.brand === undefined || method.last4 === undefined)
return coded('paymentMethodType', method.type)
return t('hosted.paymentMethods.card', {
brand: method.brand,
last4: method.last4
})
}

function portalReturnUrl(): string {
const url = new URL(window.location.href)
url.searchParams.set(PORTAL_PARAM, PORTAL_RETURN)
return url.href
}

async function openPortal() {
openingPortal.value = true
portalFailure.value = undefined
const result = await commands.openPaymentPortal({
returnUrl: portalReturnUrl()
})
openingPortal.value = false
if (result.status === 'error') {
portalFailure.value = coded('failure', result.code)
return
}
window.location.assign(result.value.url)
}

async function resumeFromPortal() {
await invalidateAndRefresh()
await router.replace({
path: route.path,
query: Object.fromEntries(
Object.entries(route.query).filter(([key]) => key !== PORTAL_PARAM)
)
})
}

if (returningFromPortal) void resumeFromPortal()
</script>

<template>
<section class="flex flex-col gap-4">
<p v-if="loading" class="m-0 text-sm text-muted-foreground">
{{ t('hosted.loading') }}
</p>
<p v-if="failure" class="m-0 text-sm text-destructive-background">
{{ coded('failure', failure.code) }}
</p>
<p
v-if="!loading && !failure && rows.length === 0"
class="m-0 text-sm text-muted-foreground"
>
{{ t('hosted.paymentMethods.empty') }}
</p>

<ul class="m-0 flex list-none flex-col gap-2 p-0">
<li
v-for="row in rows"
:key="row.id"
class="flex items-center justify-between gap-4 rounded-xl border border-border-subtle bg-secondary-background px-4 py-3"
>
<span class="text-sm text-base-foreground">{{ row.label }}</span>
<span v-if="row.isDefault" class="text-xs text-muted-foreground">
{{ t('hosted.paymentMethods.default') }}
</span>
</li>
</ul>

<p v-if="portalFailure" class="m-0 text-sm text-destructive-background">
{{ portalFailure }}
</p>
<button
type="button"
:disabled="openingPortal"
class="h-11 cursor-pointer self-start rounded-lg bg-base-foreground px-5 font-semibold text-base-background disabled:cursor-not-allowed disabled:opacity-40"
@click="openPortal"
>
{{ t('hosted.paymentMethods.manage') }}
</button>
</section>
</template>
53 changes: 53 additions & 0 deletions apps/billing-web/src/components/PlanCard.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<script setup lang="ts">
import { useI18n } from 'vue-i18n'

import { cn } from '@comfyorg/tailwind-utils'

const { name, current, available } = defineProps<{
name: string
price: string
credits: string
seats: string
available: boolean
current: boolean
/** Why the workspace cannot move to this plan, when it cannot. */
reason?: string
}>()

defineEmits<{ choose: [] }>()

const { t } = useI18n()
</script>

<template>
<li
:class="
cn(
'flex flex-col rounded-xl border border-border-subtle bg-secondary-background p-4',
current && 'border-base-foreground'
)
"
>
<h3 class="m-0 text-base font-semibold text-base-foreground">{{ name }}</h3>
<p class="mt-2 mb-0 font-semibold text-base-foreground tabular-nums">
{{ price }}
</p>
<p class="mt-1 mb-0 text-sm text-muted-foreground">{{ credits }}</p>
<p class="mt-1 mb-0 text-sm text-muted-foreground">{{ seats }}</p>
<p v-if="current" class="mt-2 mb-0 text-sm text-base-foreground">
{{ t('hosted.subscription.currentPlan') }}
</p>
<p v-if="reason" class="mt-2 mb-0 text-sm text-muted-foreground">
{{ reason }}
</p>
<button
type="button"
:disabled="!available"
:aria-label="t('hosted.subscription.choosePlan', { plan: name })"
class="mt-3 h-10 w-full cursor-pointer rounded-lg bg-base-foreground px-4 text-sm font-semibold text-base-background disabled:cursor-not-allowed disabled:opacity-40"
@click="$emit('choose')"
>
{{ t('hosted.subscription.choose') }}
</button>
</li>
</template>
Loading
Loading