Every file the pipeline and the clip editor write is now clean. On the free plan the served file is a wm_<final> copy with the mark burned in (main.mark_delivery, last step after captions; app._deliver for the editor endpoints, decided from the caller's plan), and both twins go to R2. An upgrade re-points the user's library at the clean twins from the Stripe webhook (cloud.videos.unmark_user_library): no render, no source video, and the dashboard chases the job result until no served URL carries wm_. Before, the mark rode the reframe encode, so every derivative inherited it and the upgrade modal's "upgrade to remove the watermark" was false for the clips already made. The first cancellation for "clip quality" (29-sep) was a user who paid 15 minutes after their first job and kept the mark on every download and restyle. - /videos guard refuses a marked job's clean deliverables (.marked dotfile), so the twin cannot be fetched by stripping the prefix off a URL; editor scratch files stay servable. Re-checked after an R2 restore. - Walk-backs treat wm_ as the outermost layer; _canonical_clip_file globs it. - Jobs from before this scheme (mark burned into the canonical) never get a second copy; a failed mark still serves under the wm_ name. - Watermark notice once per job when the clips land on a free account, and before the first download if skipped; tracked with source=results|download. Upsell/banner/win-back copy now promise the instant removal.
226 lines
11 KiB
JavaScript
226 lines
11 KiB
JavaScript
import React, { useState, useEffect } from 'react';
|
||
import { Loader2, Check, Zap, Clock } from 'lucide-react';
|
||
import { apiJson } from '../lib/api';
|
||
import { track } from '../lib/analytics';
|
||
import Modal from './ui/Modal';
|
||
|
||
// Opens when a job hits a 402 (quota exceeded). This is the highest-intent
|
||
// moment in the product — the user WANTS to clip a video and can't — so it
|
||
// sells the subscription first (recurring value: minutes, no watermark,
|
||
// permanent clips) and keeps one-time top-ups as a secondary escape hatch.
|
||
//
|
||
// Conversion techniques used (all honest — no fake scarcity or countdowns):
|
||
// - Goal-gradient: copy centers on finishing THIS video, not abstract quota.
|
||
// - Compromise effect: all three tiers shown, creator highlighted in the
|
||
// middle — starter floors the price, pro anchors it, creator reads as the
|
||
// sensible pick (and matches the pricing page's "most popular").
|
||
// - Outcome framing: every line says what the user GETS (clips ready to post,
|
||
// a library that stays), with the free-plan fact stated second. The earlier
|
||
// copy led with what free costs them, which reads as "pay to undo the
|
||
// restrictions we added" — the losing side of an argument against our own
|
||
// MIT repo, whose headline is literally "no watermarks, no limits".
|
||
// - Risk reversal: "cancel anytime" on the CTA.
|
||
//
|
||
// Deliberately NOT sold here: GPU rendering and the included Gemini key. Both
|
||
// are real and both are why the cloud beats self-hosting, but the free plan
|
||
// already gets them (the pricing page says "Same GPU rendering" on the free
|
||
// tier) — so they belong on the landing/pricing surface facing repo visitors,
|
||
// not in a modal shown to someone who is already using them.
|
||
const PLAN_BLURBS = {
|
||
starter: 'for getting started',
|
||
creator: 'for daily posting',
|
||
pro: 'for power users',
|
||
};
|
||
|
||
// context: 'wall' (default) = user hit the 402 quota wall mid-task.
|
||
// 'upsell' = user opened it voluntarily (results banner, header meter)
|
||
// — different framing: they still HAVE minutes, sell the watermark
|
||
// removal + permanence instead of "you ran out".
|
||
// partialMinutes / onPartial: the server's offer to clip only the first N
|
||
// minutes of the blocked video on the minutes the user has (see
|
||
// app.partial_offer). Most walls open on an account that has not spent a
|
||
// single free minute and pasted a 21-90 min video (93 of 99 sampled,
|
||
// 16-sep-2026): they are being asked to pay before seeing one clip. The offer
|
||
// turns that wall into a first run; the plans stay the way to the whole video.
|
||
export default function TopUpModal({ onClose, required, remaining, partialMinutes = 0, onPartial = null,
|
||
context = 'wall' }) {
|
||
const [plans, setPlans] = useState([]);
|
||
const [topups, setTopups] = useState([]);
|
||
const [showTopups, setShowTopups] = useState(false);
|
||
const [busyPrice, setBusyPrice] = useState(null);
|
||
const isUpsell = context === 'upsell';
|
||
|
||
useEffect(() => {
|
||
track(isUpsell ? 'UpsellModalSeen' : 'QuotaWallSeen',
|
||
{ props: { required: required ?? null, remaining: remaining ?? null } });
|
||
apiJson('/api/billing/plans')
|
||
.then((d) => {
|
||
const monthly = (d.plans || []).filter((p) => p.interval === 'month');
|
||
setPlans(['starter', 'creator', 'pro']
|
||
.map((name) => monthly.find((p) => p.plan === name))
|
||
.filter(Boolean));
|
||
setTopups(d.topups || []);
|
||
})
|
||
.catch(() => {});
|
||
// Plans are fetched once per open; the props only shape the copy.
|
||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||
}, []);
|
||
|
||
// Instrumented in three steps on purpose. Between 25-jul and 1-ago the modals
|
||
// logged 35 checkout clicks and Stripe recorded ONE new subscription, and
|
||
// nothing in between was measured — this modal fired only its own
|
||
// *ModalCheckout event, so "clicked but never reached Stripe" and "reached
|
||
// Stripe and abandoned" were indistinguishable. CheckoutStarted (click, same
|
||
// meaning as PricingSection's) → CheckoutRedirected (we hold a Stripe URL) →
|
||
// CheckoutFailed (we don't) separates them.
|
||
const source = isUpsell ? 'upsell' : 'wall';
|
||
|
||
const buy = async (entry, kind) => {
|
||
setBusyPrice(entry.price_id);
|
||
const props = { kind, plan: entry.plan || null, minutes: entry.minutes, source };
|
||
track(isUpsell ? 'UpsellModalCheckout' : 'QuotaWallCheckout', { props });
|
||
track('CheckoutStarted', { props });
|
||
// Same stash PricingSection sets, so a plan bought from the modal also
|
||
// carries its price into the Subscribed goal (AccountPage reads it back).
|
||
// Top-ups deliberately don't set it — they never count as a subscription.
|
||
if (kind === 'subscription') {
|
||
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.');
|
||
}
|
||
};
|
||
|
||
const fmt = (a, c) => new Intl.NumberFormat('en-US', {
|
||
style: 'currency', currency: (c || 'usd').toUpperCase(), maximumFractionDigits: 0,
|
||
}).format((a || 0) / 100);
|
||
|
||
const blockedByLength = typeof required === 'number' && typeof remaining === 'number';
|
||
const partialOffer = !isUpsell && partialMinutes > 0 && typeof onPartial === 'function';
|
||
const remainingShown = Math.max(0, Math.round((remaining || 0) * 10) / 10);
|
||
|
||
return (
|
||
<Modal isOpen onClose={onClose} eyebrow="UPGRADE"
|
||
title={isUpsell ? 'Keep your clips forever' : 'Your video is ready to clip'} size="xl">
|
||
{/* Goal-gradient framing: they're one step from the thing they came for. */}
|
||
<p className="text-muted text-sm mb-5">
|
||
{isUpsell
|
||
? <>Every clip comes out <b className="text-ink font-medium">ready to post</b> and stays in your
|
||
library for good. On the free plan they carry a watermark and are deleted after 7 days;
|
||
upgrade now and the clips you already made <b className="text-ink font-medium">lose the mark on the spot</b>.</>
|
||
: blockedByLength
|
||
? <>This video is <b className="text-ink font-medium">{required} min</b> long and you have{' '}
|
||
<b className="text-ink font-medium">{remainingShown} min</b> this month. Pick a plan and the
|
||
whole video starts rendering right away.</>
|
||
: <>You've used your free minutes for this month. Pick a plan and keep clipping right away.</>}
|
||
</p>
|
||
|
||
{partialOffer && (
|
||
<div className="mb-5 card p-4 flex flex-col sm:flex-row sm:items-center gap-3">
|
||
<div className="flex-1 text-sm text-ink2">
|
||
<b className="text-ink font-medium">Or see it first:</b> clip the first{' '}
|
||
<b className="text-ink font-medium">{partialMinutes} min</b> now with the minutes you have,
|
||
and decide with the clips in front of you.
|
||
</div>
|
||
<button onClick={onPartial} disabled={busyPrice !== null}
|
||
className="btn-ghost whitespace-nowrap">
|
||
Clip the first {partialMinutes} min
|
||
</button>
|
||
</div>
|
||
)}
|
||
|
||
<div className="grid sm:grid-cols-3 gap-3">
|
||
{plans.map((entry) => {
|
||
const highlight = entry.plan === 'creator';
|
||
return (
|
||
<div key={entry.price_id}
|
||
className={`relative card p-5 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-lg text-ink">{entry.plan}</h3>
|
||
<p className="text-muted text-xs mb-3 lowercase">{PLAN_BLURBS[entry.plan] || ''}</p>
|
||
<div className="mb-3 flex items-baseline gap-1.5">
|
||
<span className="font-display text-3xl text-ink tabular-nums">{fmt(entry.amount, entry.currency)}</span>
|
||
<span className="readout">/mo</span>
|
||
</div>
|
||
<ul className="space-y-1.5 text-sm text-ink2 mb-4 flex-1">
|
||
<li className="flex items-start gap-2">
|
||
<Check size={15} className="text-ok shrink-0 mt-0.5" />
|
||
<span><b>{entry.minutes} min</b> every month ({Math.round(entry.minutes / 20)}× your free quota)</span>
|
||
</li>
|
||
<li className="flex items-start gap-2">
|
||
<Check size={15} className="text-ok shrink-0 mt-0.5" />
|
||
<span>Clips <b>ready to post</b>, with no watermark</span>
|
||
</li>
|
||
<li className="flex items-start gap-2">
|
||
<Check size={15} className="text-ok shrink-0 mt-0.5" />
|
||
<span>Your library <b>stays</b> (free clips delete after 7 days)</span>
|
||
</li>
|
||
<li className="flex items-start gap-2">
|
||
<Zap size={15} className="text-brass shrink-0 mt-0.5" />
|
||
<span>Skips the free queue</span>
|
||
</li>
|
||
</ul>
|
||
<button onClick={() => buy(entry, 'subscription')} disabled={busyPrice !== null}
|
||
className={`w-full ${highlight ? 'btn-primary' : 'btn-ghost'}`}>
|
||
{busyPrice === entry.price_id
|
||
? <Loader2 size={18} className="animate-spin" />
|
||
: `Get ${entry.plan}`}
|
||
</button>
|
||
<p className="text-center text-xs text-muted mt-2 lowercase">cancel anytime.</p>
|
||
</div>
|
||
);
|
||
})}
|
||
{plans.length === 0 && (
|
||
<div className="sm:col-span-3 flex justify-center py-8">
|
||
<Loader2 className="animate-spin text-brass" />
|
||
</div>
|
||
)}
|
||
</div>
|
||
|
||
{/* Secondary escape hatch: one-time packs, deliberately de-emphasized. */}
|
||
<div className="mt-4 text-center">
|
||
{!showTopups ? (
|
||
<button onClick={() => setShowTopups(true)}
|
||
className="text-xs text-muted underline underline-offset-2 lowercase hover:text-ink2">
|
||
just need a few extra minutes? one-time packs
|
||
</button>
|
||
) : (
|
||
<div className="grid grid-cols-2 gap-3 mt-2">
|
||
{topups.map((t) => (
|
||
<button key={t.price_id} onClick={() => buy(t, 'topup')} disabled={busyPrice !== null}
|
||
className="border border-rule hover:border-brass rounded-card p-3 text-left transition-colors disabled:opacity-50">
|
||
<div className="text-ink text-sm font-medium flex items-center gap-1.5">
|
||
<Clock size={14} className="text-muted" />+{t.minutes} min
|
||
</div>
|
||
<div className="readout mt-0.5">{fmt(t.amount, t.currency)} · one-time</div>
|
||
</button>
|
||
))}
|
||
{topups.length === 0 && (
|
||
<div className="col-span-2 flex justify-center py-3">
|
||
<Loader2 className="animate-spin text-brass" size={18} />
|
||
</div>
|
||
)}
|
||
</div>
|
||
)}
|
||
</div>
|
||
</Modal>
|
||
);
|
||
}
|