clipwright/dashboard/src/components/PricingSection.jsx
juancarlos.cavero db3e7849af feat(billing): measure the click-to-Stripe gap, and sell the outcome
Between 25-jul and 1-ago the upgrade modals logged 35 checkout clicks and
Stripe recorded one new subscription. Nothing in between was measured:
TopUpModal fired only QuotaWallCheckout/UpsellModalCheckout, and
CheckoutStarted lived exclusively in PricingSection, so the funnel could
not tell "never reached Stripe" from "reached Stripe and abandoned".

Both surfaces now emit the same chain — CheckoutStarted (click) ->
CheckoutRedirected (we hold a Stripe URL) -> CheckoutFailed (we don't,
with the reason) — segmented by a `source` prop of wall | upsell |
pricing. The modal also writes the os_pending_checkout stash that
PricingSection already wrote, so a plan bought from a modal stops losing
its revenue attribution on the Subscribed goal.

The modal copy now leads with what the user gets (clips ready to post, a
library that stays) and states the free-plan limit second. Leading with
the watermark and the 7-day deletion framed the paid tier as "pay to undo
restrictions we added", which is the losing side of an argument against
our own MIT repo, whose headline is "no watermarks, no limits".

GPU rendering and the bundled Gemini key stay out of the modal on
purpose: they are the real reasons the cloud beats self-hosting, but the
free plan already gets both, so they belong on the pricing surface facing
repo visitors rather than in a modal shown to someone already using them.
2026-08-02 01:27:35 +02:00

187 lines
10 KiB
JavaScript

import React, { useState, useEffect } from 'react';
import { Check, Loader2, Zap, Cpu, KeyRound, Send, HardDrive } from 'lucide-react';
import { useAuth } from '../contexts/AuthContext';
import { apiJson } from '../lib/api';
import { track } from '../lib/analytics';
import SegmentedControl from './ui/SegmentedControl';
const PLAN_ORDER = ['starter', 'creator', 'pro'];
const PLAN_BLURB = {
starter: 'For getting started',
creator: 'For regular creators',
pro: 'For power users & teams',
};
const HIGHLIGHT = 'creator';
const FREE_MINUTES = 20;
const fmt = (amount, currency) =>
new Intl.NumberFormat('en-US', { style: 'currency', currency: (currency || 'usd').toUpperCase(), maximumFractionDigits: 0 }).format((amount || 0) / 100);
// Free tier + 3 paid tiers with monthly/annual toggle. Checkout requires sign-in.
export default function PricingSection({ onRequireLogin }) {
const { isSignedIn } = useAuth();
const [plans, setPlans] = useState([]);
const [interval, setInterval] = useState('month');
const [loading, setLoading] = useState(true);
const [busyPrice, setBusyPrice] = useState(null);
useEffect(() => {
apiJson('/api/billing/plans')
.then((d) => setPlans(d.plans || []))
.catch(() => setPlans([]))
.finally(() => setLoading(false));
}, []);
const checkout = async (entry) => {
if (!isSignedIn) { onRequireLogin?.(entry.price_id); return; }
setBusyPrice(entry.price_id);
// `source` segments this surface from the two modals (see TopUpModal), which
// now emit the same three events.
const props = { plan: entry.plan, interval: entry.interval, source: 'pricing' };
track('CheckoutStarted', { props });
// Stash the price so we can attach real revenue to the Subscribed goal when
// the user returns from Stripe (see AccountPage's checkout=success handler).
try {
localStorage.setItem('os_pending_checkout', JSON.stringify({
plan: entry.plan, interval: entry.interval, amount: entry.amount, currency: entry.currency,
}));
} catch (_) { /* ignore storage errors */ }
try {
const { url } = await apiJson('/api/billing/checkout', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ price_id: entry.price_id }),
});
track('CheckoutRedirected', { props });
window.location.href = url;
} catch (e) {
track('CheckoutFailed', { props: { ...props, reason: String(e?.detail || e?.message || 'unknown').slice(0, 120) } });
setBusyPrice(null);
alert(e?.detail || 'Could not start checkout. Please try again.');
}
};
if (loading) {
return <div className="flex justify-center py-16"><Loader2 className="animate-spin text-brass" /></div>;
}
const byPlan = (plan) => plans.find((p) => p.plan === plan && p.interval === interval);
return (
<div className="max-w-5xl mx-auto">
<div className="max-w-xs mx-auto mb-10">
<SegmentedControl
size="sm"
value={interval}
onChange={setInterval}
options={[
{ value: 'month', label: 'Monthly' },
{ value: 'year', label: 'Yearly', hint: '2 months free' },
]}
/>
</div>
<div className="grid md:grid-cols-2 lg:grid-cols-4 gap-6">
{/* Free tier — no card, Google sign-in only */}
<div className="relative card p-6 flex flex-col">
<h3 className="font-display lowercase text-xl text-ink">free</h3>
<p className="text-muted text-sm mb-4 lowercase">Try it on your own videos</p>
<div className="mb-4 flex items-baseline gap-1.5">
<span className="font-display text-4xl text-ink tabular-nums">$0</span>
<span className="readout">/mo</span>
</div>
<ul className="space-y-2 text-sm text-ink2 mb-6 flex-1">
<li className="flex items-start gap-2"><Check size={16} className="text-ok shrink-0 mt-0.5" /> <span><b>{FREE_MINUTES} min</b> of video / month</span></li>
<li className="flex items-start gap-2"><Check size={16} className="text-ok shrink-0 mt-0.5" /> <span>YouTube URL or upload</span></li>
<li className="flex items-start gap-2"><Cpu size={16} className="text-ok shrink-0 mt-0.5" /> <span>Same <b>GPU rendering</b>, about 50s per 8-min video</span></li>
<li className="flex items-start gap-2"><KeyRound size={16} className="text-ok shrink-0 mt-0.5" /> <span>Gemini key included, no setup</span></li>
<li className="flex items-start gap-2"><Check size={16} className="text-ok shrink-0 mt-0.5" /> <span>No credit card — Google sign-in</span></li>
<li className="flex items-start gap-2"><Check size={16} className="text-muted shrink-0 mt-0.5" /> <span className="text-muted">Watermark · clips kept 7 days</span></li>
</ul>
<button
onClick={() => { if (!isSignedIn) { onRequireLogin?.(null); } else { window.location.hash = ''; } }}
className="w-full btn-ghost"
>
Start free
</button>
<p className="text-center text-xs text-muted mt-2 lowercase">free minutes reset monthly.</p>
</div>
{PLAN_ORDER.map((plan) => {
const entry = byPlan(plan);
if (!entry) return null;
const highlight = plan === HIGHLIGHT;
return (
<div
key={plan}
className={`relative card p-6 flex flex-col ${highlight ? 'border-brass' : ''}`}
>
{highlight && (
<span className="absolute -top-3 left-1/2 -translate-x-1/2 badge-float">
Most popular
</span>
)}
<h3 className="font-display lowercase text-xl text-ink">{plan}</h3>
<p className="text-muted text-sm mb-4 lowercase">{PLAN_BLURB[plan]}</p>
<div className="mb-4 flex items-baseline gap-1.5">
<span className="font-display text-4xl text-ink tabular-nums">{fmt(entry.amount, entry.currency)}</span>
<span className="readout">/{interval === 'month' ? 'mo' : 'yr'}</span>
</div>
<ul className="space-y-2 text-sm text-ink2 mb-6 flex-1">
<li className="flex items-start gap-2"><Check size={16} className="text-ok shrink-0 mt-0.5" /> <span><b>{entry.minutes} min</b> of video / month</span></li>
<li className="flex items-start gap-2"><Check size={16} className="text-ok shrink-0 mt-0.5" /> <span><b>No watermark</b>, no 7-day clip expiry</span></li>
<li className="flex items-start gap-2"><Cpu size={16} className="text-ok shrink-0 mt-0.5" /> <span><b>GPU rendering</b>, about 50s per 8-min video</span></li>
<li className="flex items-start gap-2"><KeyRound size={16} className="text-ok shrink-0 mt-0.5" /> <span>Gemini key + auto-posting included</span></li>
{plan === 'pro' && <li className="flex items-start gap-2"><Zap size={16} className="text-brass shrink-0 mt-0.5" /> <span>Priority processing queue</span></li>}
</ul>
<button
onClick={() => checkout(entry)}
disabled={busyPrice === entry.price_id}
className={`w-full ${highlight ? 'btn-primary' : 'btn-ghost'}`}
>
{busyPrice === entry.price_id ? <Loader2 size={18} className="animate-spin" /> : `Get ${plan}`}
</button>
<p className="text-center text-xs text-muted mt-2 lowercase">billed {interval === 'month' ? 'monthly' : 'yearly'}. cancel anytime.</p>
</div>
);
})}
</div>
{/* What every plan includes vs what's bring-your-own-key */}
<div className="mt-10 grid md:grid-cols-2 gap-4">
<div className="card p-6">
<div className="mb-4">
<span className="badge-ok"><Check size={12} /> Included in every plan</span>
</div>
<ul className="space-y-2 text-sm text-ink2">
<li className="flex items-start gap-2"><Cpu size={15} className="text-ok shrink-0 mt-0.5" /> <span><b>Our NVIDIA GPU does the rendering.</b> An 8-minute video is clipped in about 50 seconds, instead of the 5 to 8 minutes it takes on a typical CPU.</span></li>
<li className="flex items-start gap-2"><KeyRound size={15} className="text-ok shrink-0 mt-0.5" /> <span><b>The Gemini API key is included.</b> Nothing to sign up for, nothing to paste, no per-request quota of your own to babysit.</span></li>
<li className="flex items-start gap-2"><Send size={15} className="text-ok shrink-0 mt-0.5" /> <span><b>Auto-posting is already wired up</b> for TikTok, Instagram Reels and YouTube Shorts.</span></li>
<li className="flex items-start gap-2"><HardDrive size={15} className="text-ok shrink-0 mt-0.5" /> <span><b>Clips are stored and served for you</b>, ready to re-open and re-edit from any browser.</span></li>
<li className="flex items-start gap-2"><Check size={15} className="text-ok shrink-0 mt-0.5" /> <span>Full <b>YouTube Studio</b>: titles, thumbnails and descriptions.</span></li>
</ul>
<p className="text-xs text-muted mt-3 pt-3 border-t border-rule">
Your monthly minutes cover video processing. Titles &amp; descriptions are free;
AI <b>thumbnail image generation</b> uses ~3 min of your quota per batch.
</p>
</div>
<div className="card p-6">
<div className="mb-4">
<span className="badge-warn"><Zap size={12} /> Bring your own key</span>
</div>
<p className="text-sm text-muted mb-3 leading-relaxed">
<b className="text-ink2">AI Shorts</b> (AI-actor UGC videos) and <b className="text-ink2">voice dubbing</b> use premium generation from
<b className="text-ink2"> fal.ai</b> and <b className="text-ink2">ElevenLabs</b>. Connect your own keys for those — you're billed by those
providers directly (typically ~$0.65-2 per video). Your plan still covers the script &amp; orchestration.
</p>
<p className="text-xs text-muted">Managed credits for these are coming later — no keys needed.</p>
</div>
</div>
<p className="text-center text-muted text-xs mt-8 lowercase">
start free right here, upgrade for more minutes and no watermark, or run it yourself on your own hardware.
</p>
</div>
);
}