-
Notifications
You must be signed in to change notification settings - Fork 439
feat: replace Stripe pricing table with custom implementation #7359
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
65a6cca
feat: replace Stripe pricing table with custom implementation
christian-byrne b6f73a1
fix: await JSON parsing in checkout API call
christian-byrne 7e4912e
fix: add missing videoEstimate i18n keys and remove hardcoded value
christian-byrne 8b7194e
fix: improve error handling for non-JSON API responses
christian-byrne d3afe2b
fix: correct FOUNDERS_EDITION handling and polling behavior
christian-byrne File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
260 changes: 260 additions & 0 deletions
260
src/platform/cloud/subscription/components/PricingTable.vue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,260 @@ | ||
| <template> | ||
| <div class="flex flex-row items-stretch gap-6"> | ||
| <div | ||
| v-for="tier in tiers" | ||
| :key="tier.id" | ||
| class="flex-1 flex flex-col rounded-2xl border border-interface-stroke bg-interface-panel-surface shadow-[0_0_12px_rgba(0,0,0,0.1)]" | ||
| > | ||
| <div class="flex flex-col gap-6 p-8"> | ||
| <div class="flex flex-row items-center gap-2"> | ||
| <span class="font-inter text-base font-bold leading-normal text-base-foreground"> | ||
| {{ tier.name }} | ||
| </span> | ||
| <div | ||
| v-if="tier.isPopular" | ||
| class="rounded-full bg-white px-1 text-xs font-semibold uppercase tracking-wide text-black h-[13px] leading-[13px]" | ||
| > | ||
| {{ t('subscription.mostPopular') }} | ||
| </div> | ||
| </div> | ||
| <div class="flex flex-row items-baseline gap-2"> | ||
| <span class="font-inter text-[32px] font-semibold leading-normal text-base-foreground"> | ||
| ${{ tier.price }} | ||
| </span> | ||
| <span class="font-inter text-base font-normal leading-normal text-base-foreground"> | ||
| {{ t('subscription.usdPerMonth') }} | ||
| </span> | ||
| </div> | ||
| </div> | ||
|
|
||
| <div class="flex flex-col gap-4 px-8 pb-0 flex-1"> | ||
| <div class="flex flex-row items-center justify-between"> | ||
| <span class="font-inter text-sm font-normal leading-normal text-muted-foreground"> | ||
| {{ t('subscription.monthlyCreditsLabel') }} | ||
| </span> | ||
| <div class="flex flex-row items-center gap-1"> | ||
| <i class="icon-[lucide--component] text-amber-400 text-sm" /> | ||
| <span class="font-inter text-sm font-bold leading-normal text-base-foreground"> | ||
| {{ tier.credits }} | ||
| </span> | ||
| </div> | ||
| </div> | ||
|
|
||
| <div class="flex flex-row items-center justify-between"> | ||
| <span class="text-sm font-normal text-muted-foreground"> | ||
| {{ t('subscription.maxDurationLabel') }} | ||
| </span> | ||
| <span class="font-inter text-sm font-bold leading-normal text-base-foreground"> | ||
| {{ tier.maxDuration }} | ||
| </span> | ||
| </div> | ||
|
|
||
| <div class="flex flex-row items-center justify-between"> | ||
| <span class="text-sm font-normal text-muted-foreground"> | ||
| {{ t('subscription.gpuLabel') }} | ||
| </span> | ||
| <i class="pi pi-check text-xs text-white" /> | ||
| </div> | ||
|
|
||
| <div class="flex flex-row items-center justify-between"> | ||
| <span class="text-sm font-normal text-muted-foreground"> | ||
| {{ t('subscription.addCreditsLabel') }} | ||
| </span> | ||
| <i class="pi pi-check text-xs text-white" /> | ||
| </div> | ||
|
|
||
| <div class="flex flex-row items-center justify-between"> | ||
| <span class="text-sm font-normal text-muted-foreground"> | ||
| {{ t('subscription.customLoRAsLabel') }} | ||
| </span> | ||
| <i v-if="tier.customLoRAs" class="pi pi-check text-xs text-white" /> | ||
| <i v-else class="pi pi-times text-xs text-muted" /> | ||
| </div> | ||
|
|
||
| <div class="flex flex-col gap-2"> | ||
| <div class="flex flex-row items-start justify-between"> | ||
| <div class="flex flex-col gap-2"> | ||
| <span class="text-sm font-normal text-muted-foreground"> | ||
| {{ t('subscription.videoEstimateLabel') }} | ||
| </span> | ||
| <div class="flex flex-row items-center gap-2 opacity-50"> | ||
| <i class="pi pi-question-circle text-xs text-muted-foreground" /> | ||
| <span class="text-sm font-normal text-muted-foreground"> | ||
| {{ t('subscription.videoEstimateHelp') }} | ||
| </span> | ||
| </div> | ||
| </div> | ||
| <span class="font-inter text-sm font-bold leading-normal text-base-foreground"> | ||
| {{ tier.videoEstimate }} | ||
| </span> | ||
| </div> | ||
| </div> | ||
| </div> | ||
|
|
||
| <div class="flex flex-col p-8"> | ||
| <Button | ||
| :label="getButtonLabel(tier)" | ||
| :severity="getButtonSeverity(tier)" | ||
| :disabled="isLoading || isCurrentPlan(tier.key)" | ||
| :loading="loadingTier === tier.key" | ||
| class="h-10 w-full" | ||
| :pt="{ | ||
| label: { | ||
| class: 'font-inter text-sm font-bold leading-normal text-white' | ||
| } | ||
| }" | ||
| @click="() => handleSubscribe(tier.key)" | ||
| /> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </template> | ||
|
|
||
| <script setup lang="ts"> | ||
| import Button from 'primevue/button' | ||
| import { computed, ref } from 'vue' | ||
| import { useFirebaseAuthActions } from '@/composables/auth/useFirebaseAuthActions' | ||
| import { useErrorHandling } from '@/composables/useErrorHandling' | ||
| import { getComfyApiBaseUrl } from '@/config/comfyApi' | ||
| import { t } from '@/i18n' | ||
| import { useSubscription } from '@/platform/cloud/subscription/composables/useSubscription' | ||
| import { isCloud } from '@/platform/distribution/types' | ||
| import { | ||
| FirebaseAuthStoreError, | ||
| useFirebaseAuthStore | ||
| } from '@/stores/firebaseAuthStore' | ||
| import type { components } from '@/types/comfyRegistryTypes' | ||
christian-byrne marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| type SubscriptionTier = components['schemas']['SubscriptionTier'] | ||
| type TierKey = 'standard' | 'creator' | 'pro' | ||
| interface PricingTierConfig { | ||
| id: SubscriptionTier | ||
| key: TierKey | ||
| name: string | ||
| price: string | ||
| credits: string | ||
| maxDuration: string | ||
| customLoRAs: boolean | ||
| videoEstimate: string | ||
| isPopular?: boolean | ||
| } | ||
| const TIER_TO_KEY: Record<SubscriptionTier, TierKey> = { | ||
| STANDARD: 'standard', | ||
| CREATOR: 'creator', | ||
| PRO: 'pro', | ||
| FOUNDERS_EDITION: 'creator' | ||
| } | ||
| const tiers: PricingTierConfig[] = [ | ||
| { | ||
| id: 'STANDARD', | ||
| key: 'standard', | ||
| name: t('subscription.tiers.standard.name'), | ||
| price: t('subscription.tiers.standard.price'), | ||
| credits: t('subscription.credits.standard'), | ||
| maxDuration: t('subscription.maxDuration.standard'), | ||
| customLoRAs: false, | ||
| videoEstimate: t('subscription.tiers.standard.benefits.videoEstimate'), | ||
| isPopular: false | ||
| }, | ||
| { | ||
| id: 'CREATOR', | ||
| key: 'creator', | ||
| name: t('subscription.tiers.creator.name'), | ||
| price: t('subscription.tiers.creator.price'), | ||
| credits: t('subscription.credits.creator'), | ||
| maxDuration: t('subscription.maxDuration.creator'), | ||
| customLoRAs: true, | ||
| videoEstimate: '288', | ||
christian-byrne marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| isPopular: true | ||
| }, | ||
| { | ||
| id: 'PRO', | ||
| key: 'pro', | ||
| name: t('subscription.tiers.pro.name'), | ||
| price: t('subscription.tiers.pro.price'), | ||
| credits: t('subscription.credits.pro'), | ||
| maxDuration: t('subscription.maxDuration.pro'), | ||
| customLoRAs: true, | ||
| videoEstimate: t('subscription.tiers.pro.benefits.videoEstimate'), | ||
| isPopular: false | ||
| } | ||
| ] | ||
christian-byrne marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const { getAuthHeader } = useFirebaseAuthStore() | ||
| const { isActiveSubscription, subscriptionTier } = useSubscription() | ||
| const { accessBillingPortal, reportError } = useFirebaseAuthActions() | ||
| const { wrapWithErrorHandlingAsync } = useErrorHandling() | ||
| const isLoading = ref(false) | ||
| const loadingTier = ref<TierKey | null>(null) | ||
| const currentTierKey = computed<TierKey | null>(() => | ||
| subscriptionTier.value ? TIER_TO_KEY[subscriptionTier.value] : null | ||
| ) | ||
| const isCurrentPlan = (tierKey: TierKey): boolean => | ||
| currentTierKey.value === tierKey | ||
| const getButtonLabel = (tier: PricingTierConfig): string => { | ||
| if (isCurrentPlan(tier.key)) return t('subscription.currentPlan') | ||
| if (!isActiveSubscription.value) return t('subscription.subscribeTo', { plan: tier.name }) | ||
| return t('subscription.changeTo', { plan: tier.name }) | ||
| } | ||
| const getButtonSeverity = (tier: PricingTierConfig): 'primary' | 'secondary' => | ||
| isCurrentPlan(tier.key) ? 'secondary' : tier.key === 'creator' ? 'primary' : 'secondary' | ||
| const initiateCheckout = async (tierKey: TierKey) => { | ||
| const authHeader = await getAuthHeader() | ||
| if (!authHeader) { | ||
| throw new FirebaseAuthStoreError(t('toastMessages.userNotAuthenticated')) | ||
| } | ||
| const response = await fetch( | ||
| `${getComfyApiBaseUrl()}/customers/cloud-subscription-checkout/${tierKey}`, | ||
| { | ||
| method: 'POST', | ||
| headers: { ...authHeader, 'Content-Type': 'application/json' } | ||
| } | ||
| ) | ||
| if (!response.ok) { | ||
| const errorData = await response.json() | ||
| throw new FirebaseAuthStoreError( | ||
| t('toastMessages.failedToInitiateSubscription', { | ||
| error: errorData.message || 'Failed to initiate checkout' | ||
| }) | ||
| ) | ||
| } | ||
christian-byrne marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return response.json() | ||
| } | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const handleSubscribe = wrapWithErrorHandlingAsync( | ||
| async (tierKey: TierKey) => { | ||
| if (!isCloud || isLoading.value || isCurrentPlan(tierKey)) return | ||
| isLoading.value = true | ||
| loadingTier.value = tierKey | ||
| try { | ||
| if (isActiveSubscription.value) { | ||
| await accessBillingPortal() | ||
| } else { | ||
| const response = await initiateCheckout(tierKey) | ||
| if (response.checkout_url) { | ||
| window.open(response.checkout_url, '_blank') | ||
| } | ||
| } | ||
| } finally { | ||
| isLoading.value = false | ||
| loadingTier.value = null | ||
| } | ||
| }, | ||
| reportError | ||
| ) | ||
| </script> | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.