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
14 changes: 7 additions & 7 deletions apps/mobile/components/upgrade/plan-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ export function PlanCard({
const styles = StyleSheet.create({
card: {
borderRadius: 18,
paddingTop: 18,
paddingHorizontal: 18,
paddingBottom: 20,
paddingTop: 20,
paddingHorizontal: 20,
paddingBottom: 22,
},
cardPressed: {
transform: [{ scale: 0.99 }],
Expand All @@ -107,7 +107,7 @@ const styles = StyleSheet.create({
flexDirection: 'row',
alignItems: 'center',
gap: 8,
marginBottom: 6,
marginBottom: 8,
},
name: {
fontFamily: 'Rubik_500Medium',
Expand All @@ -120,7 +120,7 @@ const styles = StyleSheet.create({
sub: {
fontFamily: 'Rubik_400Regular',
fontSize: 13,
marginTop: 2,
marginTop: 4,
},
radio: {
width: 24,
Expand All @@ -135,8 +135,8 @@ const styles = StyleSheet.create({
borderRadius: radius.full,
},
features: {
marginTop: 14,
gap: 9,
marginTop: 16,
gap: 10,
},
featureRow: {
flexDirection: 'row',
Expand Down
3 changes: 2 additions & 1 deletion apps/mobile/components/upgrade/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ export const styles = StyleSheet.create({
},
planGroup: {
paddingHorizontal: 20,
gap: 14,
gap: 16,
marginTop: 18,
},
actionPad: {
paddingHorizontal: 20,
Expand Down
37 changes: 34 additions & 3 deletions apps/web/__tests__/pages/upgrade.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, it, expect, vi, beforeEach } from 'vitest'
import { render, screen } from '@testing-library/react'
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'
import { render, screen, fireEvent, waitFor } from '@testing-library/react'


vi.mock('next-intl', () => ({
Expand Down Expand Up @@ -73,7 +73,7 @@ vi.mock('@/hooks/use-billing', () => ({

vi.mock('@orbit/shared/api', () => ({
API: {
subscription: { checkout: '/api/subscription/checkout', portal: '/api/subscription/portal', plans: '/api/subscription/plans' },
subscription: { checkout: '/api/subscriptions/checkout', portal: '/api/subscriptions/portal', plans: '/api/subscriptions/plans' },
},
}))

Expand Down Expand Up @@ -112,6 +112,10 @@ describe('UpgradePage', () => {
mockUseBilling.mockClear()
})

afterEach(() => {
vi.unstubAllGlobals()
})

it('renders without crashing', () => {
const { container } = render(<UpgradePage />)
expect(container).toBeTruthy()
Expand Down Expand Up @@ -367,4 +371,31 @@ describe('UpgradePage', () => {
expect(screen.getByText('upgrade.billing.plan.lifetime')).toBeInTheDocument()
expect(screen.queryByText('upgrade.billing.error')).not.toBeInTheDocument()
})

it('routes checkout through the geo-forwarding BFF route, not a direct Stripe action', async () => {
mockPlans = {
monthly: { unitAmount: 999 },
yearly: { unitAmount: 4999 },
currency: 'usd',
savingsPercent: 58,
couponPercentOff: null,
}
const fetchMock = vi.fn().mockResolvedValue({
ok: true,
json: async () => ({ url: 'https://checkout.stripe.test/session' }),
})
vi.stubGlobal('fetch', fetchMock)
vi.stubGlobal('location', { href: '' })

render(<UpgradePage />)
fireEvent.click(screen.getByTestId('paywall-checkout'))

await waitFor(() => expect(fetchMock).toHaveBeenCalledTimes(1))
const call = fetchMock.mock.calls[0]
const requestUrl = String(call?.[0])
const requestInit = call?.[1] as RequestInit | undefined
expect(requestUrl.startsWith('/api/subscriptions/checkout')).toBe(true)
expect(requestInit?.method).toBe('POST')
expect(JSON.parse(String(requestInit?.body))).toEqual({ interval: 'yearly' })
})
})
18 changes: 16 additions & 2 deletions apps/web/app/(app)/upgrade/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ import { BillingDashboard } from '@/components/upgrade/billing-dashboard'
import { PlayBillingDashboard } from '@/components/upgrade/play-billing-dashboard'
import { PricingSection } from '@/components/upgrade/pricing-section'
import {
createApiClientError,
getClientTimeZone,
getFriendlyErrorMessage,
} from '@orbit/shared/utils'
import { API } from '@orbit/shared/api'
import { useProfile, useHasProAccess, useTrialDaysLeft } from '@/hooks/use-profile'
import { useSubscriptionPlans } from '@/hooks/use-subscription-plans'
import { useBilling } from '@/hooks/use-billing'
import { createCheckoutSession, openCustomerPortal } from '@/app/actions/subscription'
import { openCustomerPortal } from '@/app/actions/subscription'
import { useGoBackOrFallback } from '@/hooks/use-go-back-or-fallback'

type SubscriptionInterval = 'monthly' | 'yearly'
Expand Down Expand Up @@ -52,7 +54,19 @@ export default function UpgradePage() {
setCheckoutError('')
try {
const timeZone = getClientTimeZone()
const data = await createCheckoutSession(interval, timeZone)
const checkoutUrl = timeZone
? `${API.subscription.checkout}?timeZone=${encodeURIComponent(timeZone)}`
: API.subscription.checkout
const response = await fetch(checkoutUrl, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ interval }),
})
if (!response.ok) {
const errorBody = await response.json().catch(() => null)
throw createApiClientError(response.status, errorBody, `Failed with status ${response.status}`)
}
const data = (await response.json()) as { url?: string }
if (data?.url) {
globalThis.location.href = data.url
}
Expand Down
18 changes: 0 additions & 18 deletions apps/web/app/actions/subscription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,10 @@
import { API } from '@orbit/shared/api'
import { serverAuthFetch } from '@/lib/server-fetch'

export interface CheckoutResponse {
url: string
}

export interface PortalResponse {
url: string
}

export async function createCheckoutSession(
interval: 'monthly' | 'yearly',
timeZone?: string | null,
): Promise<CheckoutResponse> {
const url = timeZone
? `${API.subscription.checkout}?timeZone=${encodeURIComponent(timeZone)}`
: API.subscription.checkout
return serverAuthFetch(url, {
method: 'POST',
headers: timeZone ? { 'x-client-timezone': timeZone } : undefined,
body: JSON.stringify({ interval }),
})
}

export async function openCustomerPortal(): Promise<PortalResponse> {
return serverAuthFetch(API.subscription.portal, { method: 'POST' })
}
16 changes: 8 additions & 8 deletions apps/web/components/upgrade/plan-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export function PlanCard({
const isHero = variant === 'hero'

return (
<div className={['flex h-full flex-col rounded-[18px] p-[18px]', cardOrder[variant], surface[variant]].join(' ')}>
<div className={['flex h-full flex-col rounded-[18px] p-[22px]', cardOrder[variant], surface[variant]].join(' ')}>
<div className="flex flex-wrap items-center gap-2" style={{ minHeight: 24 }}>
<span
style={{
Expand All @@ -66,7 +66,7 @@ export function PlanCard({
{badge ? <Badge>{badge}</Badge> : null}
</div>

<div className="flex items-baseline gap-1" style={{ marginTop: 10 }}>
<div className="flex items-baseline gap-1" style={{ marginTop: 14 }}>
<span
style={{
fontFamily: 'var(--font-display)',
Expand All @@ -82,33 +82,33 @@ export function PlanCard({
</div>

{sub ? (
<p style={{ margin: '4px 0 0', fontFamily: 'var(--font-sans)', fontSize: 12.5, lineHeight: 1.45, color: 'var(--fg-3)' }}>
<p style={{ margin: '6px 0 0', fontFamily: 'var(--font-sans)', fontSize: 13, lineHeight: 1.5, color: 'var(--fg-3)' }}>
{sub}
</p>
) : null}

{heroLine ? (
<div
className="flex items-start gap-2"
style={{ marginTop: 14, paddingTop: 14, borderTop: '1px solid var(--hairline)' }}
style={{ marginTop: 16, paddingTop: 16, borderTop: '1px solid var(--hairline)' }}
>
<Sparkles size={15} strokeWidth={1.8} className="shrink-0 text-[var(--primary-soft)]" style={{ marginTop: 1 }} aria-hidden="true" />
<span style={{ fontFamily: 'var(--font-sans)', fontSize: 12.5, lineHeight: 1.4, color: 'var(--fg-2)' }}>{heroLine}</span>
<span style={{ fontFamily: 'var(--font-sans)', fontSize: 13, lineHeight: 1.45, color: 'var(--fg-2)' }}>{heroLine}</span>
</div>
) : null}

{features.length > 0 ? (
<ul className="flex flex-col" style={{ marginTop: 14, gap: 8 }}>
<ul className="flex flex-col" style={{ marginTop: 16, gap: 10 }}>
{features.map((feature) => (
<li key={feature} className="flex items-center" style={{ gap: 8 }}>
<Check size={14} strokeWidth={2.4} className="shrink-0 text-[var(--primary-soft)]" aria-hidden="true" />
<span style={{ fontFamily: 'var(--font-sans)', fontSize: 12.5, color: 'var(--fg-2)' }}>{feature}</span>
<span style={{ fontFamily: 'var(--font-sans)', fontSize: 13, color: 'var(--fg-2)' }}>{feature}</span>
</li>
))}
</ul>
) : null}

<div style={{ marginTop: 'auto', paddingTop: 16 }}>
<div style={{ marginTop: 'auto', paddingTop: 20 }}>
<PillButton
variant={isHero ? 'primary' : 'ghost'}
fullWidth
Expand Down
2 changes: 1 addition & 1 deletion apps/web/components/upgrade/plan-selection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function PlanSelection({
const marquee = UPGRADE_PRO_FEATURES.map((feature) => t(`upgrade.plans.proFeatures.${feature.key}`))

return (
<div className="grid grid-cols-1 items-stretch stagger-enter sm:grid-cols-3" style={{ gap: 12 }}>
<div className="grid grid-cols-1 items-stretch stagger-enter sm:grid-cols-3" style={{ gap: 16 }}>
<PlanCard
variant="free"
name={t('upgrade.free')}
Expand Down
8 changes: 4 additions & 4 deletions apps/web/components/upgrade/pricing-section.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export function PricingSection({

return (
<>
<header style={{ marginBottom: 18 }}>
<header style={{ marginBottom: 20 }}>
<p className="t-eyebrow" style={{ margin: 0, color: 'var(--primary-soft)' }}>
{eyebrow}
</p>
Expand All @@ -65,9 +65,9 @@ export function PricingSection({
</header>

{isLoadingPlans ? (
<div className="grid grid-cols-1 sm:grid-cols-3" style={{ gap: 12 }}>
<div className="grid grid-cols-1 sm:grid-cols-3" style={{ gap: 16 }}>
{[1, 2, 3].map((i) => (
<div key={i} className="rounded-[18px]" style={{ padding: '18px', ...cardSurface }}>
<div key={i} className="rounded-[18px]" style={{ padding: '22px', ...cardSurface }}>
<div className="skeleton-pulse h-4 w-20 rounded" style={{ background: 'var(--bg-elev-2)' }} />
<div className="skeleton-pulse mt-3 h-7 w-24 rounded" style={{ background: 'var(--bg-elev-2)' }} />
<div className="skeleton-pulse mt-5 h-9 w-full rounded-full" style={{ background: 'var(--bg-elev-2)' }} />
Expand Down Expand Up @@ -100,7 +100,7 @@ export function PricingSection({
t={t}
/>

<div className="flex flex-col items-center" style={{ gap: 6, marginTop: 16 }}>
<div className="flex flex-col items-center" style={{ gap: 6, marginTop: 20 }}>
{plans.couponPercentOff ? (
<p
className="flex items-center justify-center"
Expand Down
8 changes: 4 additions & 4 deletions packages/shared/src/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1586,14 +1586,14 @@
"trialDaysLeft": "Pro Trial · {days} day left | Pro Trial · {days} days left",
"trialLastDay": "Pro Trial · last day",
"trialHeading": "Keep your Pro features",
"trialCta": "Subscribe to keep Pro",
"trialCta": "Keep Pro",
"freeEyebrow": "Free plan",
"freeHeading": "Your Pro trial ended",
"freeCta": "Upgrade to Pro",
"freeCta": "Get Pro",
"trustLine": "No card was ever taken, you dropped to Free automatically.",
"cancelAnytime": "Cancel anytime",
"noCardCancel": "No card required · Cancel anytime",
"stayFree": "Stay on Free"
"stayFree": "Stay free"
},
"matrix": {
"title": "Compare every feature",
Expand All @@ -1608,7 +1608,7 @@
"monthly": {
"name": "Pro Monthly",
"period": "/mo",
"cta": "Subscribe Monthly",
"cta": "Subscribe",
"note": "Billed monthly"
},
"yearly": {
Expand Down
8 changes: 4 additions & 4 deletions packages/shared/src/i18n/pt-BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -1586,14 +1586,14 @@
"trialDaysLeft": "Teste Pro · {days} dia restante | Teste Pro · {days} dias restantes",
"trialLastDay": "Teste Pro · último dia",
"trialHeading": "Mantenha seus recursos Pro",
"trialCta": "Assinar para manter o Pro",
"trialCta": "Manter o Pro",
"freeEyebrow": "Plano grátis",
"freeHeading": "Seu teste Pro acabou",
"freeCta": "Fazer upgrade para o Pro",
"freeCta": "Assinar Pro",
"trustLine": "Nenhum cartão foi cobrado, você voltou ao plano grátis automaticamente.",
"cancelAnytime": "Cancele quando quiser",
"noCardCancel": "Sem cartão · Cancele quando quiser",
"stayFree": "Continuar no plano grátis"
"stayFree": "Continuar grátis"
},
"matrix": {
"title": "Compare todos os recursos",
Expand All @@ -1608,7 +1608,7 @@
"monthly": {
"name": "Pro Mensal",
"period": "/mês",
"cta": "Assinar Mensal",
"cta": "Assinar",
"note": "Cobrado mensalmente"
},
"yearly": {
Expand Down