Spaces:
Running
Running
Commit ·
cecfe55
1
Parent(s): 30247fe
Switch the shop from Stripe to PayPal
Browse files- SETUP.html +20 -19
- js/admin.js +37 -32
- js/auth.js +1 -1
- js/cloud.js +39 -26
- js/pricing.js +1 -1
- schema.sql +44 -7
SETUP.html
CHANGED
|
@@ -274,34 +274,35 @@
|
|
| 274 |
<div class="step-head">
|
| 275 |
<div class="num">7</div>
|
| 276 |
<div>
|
| 277 |
-
<h2>
|
| 278 |
-
<p class="why">
|
| 279 |
</div>
|
| 280 |
</div>
|
| 281 |
<div class="body">
|
| 282 |
<div class="window">
|
| 283 |
-
<div class="chrome"><i></i><i></i><i></i><span class="url">
|
| 284 |
<div class="pane">
|
| 285 |
<div class="rail">
|
| 286 |
-
<div class="item on"><span class="ic">▦</span>
|
| 287 |
-
<div class="item"><span class="ic">
|
| 288 |
-
<div class="item"><span class="ic">
|
| 289 |
</div>
|
| 290 |
<div class="canvas">
|
| 291 |
-
<h4>
|
| 292 |
-
<p>
|
| 293 |
-
<div class="field"><span><span class="lab">
|
| 294 |
-
<div class="field"><span><span class="lab">
|
| 295 |
-
<div class="row"><button class="btn green">Create
|
| 296 |
</div>
|
| 297 |
</div>
|
| 298 |
</div>
|
| 299 |
<div class="do">
|
| 300 |
-
<b>Do this:</b> in
|
| 301 |
-
|
|
|
|
| 302 |
</div>
|
| 303 |
<table class="where">
|
| 304 |
-
<tr><th>Product name</th><th>Price
|
| 305 |
<tr><td>Paragraph Lite</td><td>£4.00</td><td>One-off</td></tr>
|
| 306 |
<tr><td>Model Library</td><td>£14.00</td><td>One-off</td></tr>
|
| 307 |
<tr><td>Exam Season</td><td>£24.00</td><td>One-off</td></tr>
|
|
@@ -310,7 +311,7 @@
|
|
| 310 |
<tr><td>Scholar</td><td>£9.00</td><td>Monthly, recurring</td></tr>
|
| 311 |
<tr><td>Examiner</td><td>£19.00</td><td>Monthly, recurring</td></tr>
|
| 312 |
</table>
|
| 313 |
-
<div class="tip">
|
| 314 |
</div>
|
| 315 |
</section>
|
| 316 |
|
|
@@ -319,7 +320,7 @@
|
|
| 319 |
<div class="num">8</div>
|
| 320 |
<div>
|
| 321 |
<h2>Try it, then give yourself the plan</h2>
|
| 322 |
-
<p class="why">With payment links,
|
| 323 |
</div>
|
| 324 |
</div>
|
| 325 |
<div class="body">
|
|
@@ -437,9 +438,9 @@
|
|
| 437 |
<tr><td>Prices, plan names, wording of a plan</td><td>Site → <b>Developer → Plans → Edit</b></td></tr>
|
| 438 |
<tr><td>Any sentence on any page</td><td>Site → <b>Developer → Wording → edit mode</b>, then click the words</td></tr>
|
| 439 |
<tr><td>Model keys and endpoints</td><td>Site → <b>Developer → Models & keys</b></td></tr>
|
| 440 |
-
<tr><td>Payment links</td><td>Site → <b>Developer → Plans</b> →
|
| 441 |
<tr><td>Who has a plan</td><td>Site → <b>Developer → People</b></td></tr>
|
| 442 |
-
<tr><td>
|
| 443 |
<tr><td>The project address and key</td><td>Supabase → <b>Project Settings → API</b>; site → <b>Developer → Supabase</b></td></tr>
|
| 444 |
<tr><td>Emails students receive</td><td>Supabase → <b>Authentication → Emails</b></td></tr>
|
| 445 |
<tr><td>Which address students see as the sender</td><td>Supabase → <b>Authentication → Emails → SMTP Settings</b></td></tr>
|
|
@@ -462,7 +463,7 @@
|
|
| 462 |
<tr><td>No developer console in the sidebar</td><td>You are signed in as a different email. Sign out, sign in as lucas.owen13@icloud.com.</td></tr>
|
| 463 |
<tr><td>"Supabase could not be reached"</td><td>Project URL or anon key pasted wrong. Developer → Supabase → paste again from Project Settings → API.</td></tr>
|
| 464 |
<tr><td>Plans page is empty</td><td>Step 2 did not run. Supabase → SQL Editor → paste the file → Run.</td></tr>
|
| 465 |
-
<tr><td>"This plan has no
|
| 466 |
<tr><td>Sign-up says "check your email" but nothing arrives</td><td>Confirmation is on and Supabase's built-in sender only reaches your own team. Connect Resend (last section), or turn Confirm email off in Authentication → Providers → Email.</td></tr>
|
| 467 |
</table>
|
| 468 |
</div>
|
|
|
|
| 274 |
<div class="step-head">
|
| 275 |
<div class="num">7</div>
|
| 276 |
<div>
|
| 277 |
+
<h2>Connect PayPal to the plans</h2>
|
| 278 |
+
<p class="why">Two routes: the PayPal API unlocks purchases automatically; payment links need no keys but one click per sale.</p>
|
| 279 |
</div>
|
| 280 |
</div>
|
| 281 |
<div class="body">
|
| 282 |
<div class="window">
|
| 283 |
+
<div class="chrome"><i></i><i></i><i></i><span class="url">developer.paypal.com → Apps & Credentials</span></div>
|
| 284 |
<div class="pane">
|
| 285 |
<div class="rail">
|
| 286 |
+
<div class="item on"><span class="ic">▦</span> Apps & Credentials</div>
|
| 287 |
+
<div class="item"><span class="ic">◍</span> Live</div>
|
| 288 |
+
<div class="item"><span class="ic">↗</span> Webhooks</div>
|
| 289 |
</div>
|
| 290 |
<div class="canvas">
|
| 291 |
+
<h4>Create a PayPal app</h4>
|
| 292 |
+
<p>Copy the Client ID and Secret into Supabase secrets.</p>
|
| 293 |
+
<div class="field"><span><span class="lab">Client ID</span><code>AeA1…your-client-id</code></span></div>
|
| 294 |
+
<div class="field"><span><span class="lab">Secret</span><code>••••••••••••</code></span><span class="pin">6</span></div>
|
| 295 |
+
<div class="row"><button class="btn green">Create app</button><span class="pin">7</span></div>
|
| 296 |
</div>
|
| 297 |
</div>
|
| 298 |
</div>
|
| 299 |
<div class="do">
|
| 300 |
+
<b>Do this:</b> in PayPal open <b>Developer → Apps & Credentials</b>, choose <b>Live</b> (or <b>Sandbox</b> to test), create an app, and copy the <b>Client ID</b> and <b>Secret</b> <span class="pin">6</span>. Add them as <code class="inline">PAYPAL_CLIENT_ID</code> and <code class="inline">PAYPAL_CLIENT_SECRET</code> in Supabase → <b>Edge Functions → Secrets</b> <span class="pin">7</span>.
|
| 301 |
+
Add a webhook at <code class="inline">https://YOUR-PROJECT.supabase.co/functions/v1/paypal-webhook</code> with the six payment events listed in <code class="inline">supabase/SETUP.md</code>, then put its <b>Webhook ID</b> into <code class="inline">PAYPAL_WEBHOOK_ID</code>.
|
| 302 |
+
On the site open <b>Developer → PayPal</b>, paste the <b>Client ID</b>, set <b>Live</b> and <b>PayPal API</b>, and save.
|
| 303 |
</div>
|
| 304 |
<table class="where">
|
| 305 |
+
<tr><th>Product name</th><th>Price</th><th>Type</th></tr>
|
| 306 |
<tr><td>Paragraph Lite</td><td>£4.00</td><td>One-off</td></tr>
|
| 307 |
<tr><td>Model Library</td><td>£14.00</td><td>One-off</td></tr>
|
| 308 |
<tr><td>Exam Season</td><td>£24.00</td><td>One-off</td></tr>
|
|
|
|
| 311 |
<tr><td>Scholar</td><td>£9.00</td><td>Monthly, recurring</td></tr>
|
| 312 |
<tr><td>Examiner</td><td>£19.00</td><td>Monthly, recurring</td></tr>
|
| 313 |
</table>
|
| 314 |
+
<div class="tip">No terminal? Use <b>PayPal payment links</b> instead: create a link per plan in PayPal, paste it into <b>Developer → Plans → PayPal payment link</b>, switch the checkout mode to <b>Payment links</b>, and grant each buyer in <b>People</b>. The API route is the one that unlocks automatically.</div>
|
| 315 |
</div>
|
| 316 |
</section>
|
| 317 |
|
|
|
|
| 320 |
<div class="num">8</div>
|
| 321 |
<div>
|
| 322 |
<h2>Try it, then give yourself the plan</h2>
|
| 323 |
+
<p class="why">With payment links, PayPal takes the money but the site does not hear about it automatically. You approve the buyer by hand — one click.</p>
|
| 324 |
</div>
|
| 325 |
</div>
|
| 326 |
<div class="body">
|
|
|
|
| 438 |
<tr><td>Prices, plan names, wording of a plan</td><td>Site → <b>Developer → Plans → Edit</b></td></tr>
|
| 439 |
<tr><td>Any sentence on any page</td><td>Site → <b>Developer → Wording → edit mode</b>, then click the words</td></tr>
|
| 440 |
<tr><td>Model keys and endpoints</td><td>Site → <b>Developer → Models & keys</b></td></tr>
|
| 441 |
+
<tr><td>Payment links</td><td>Site → <b>Developer → Plans</b> → PayPal payment link field</td></tr>
|
| 442 |
<tr><td>Who has a plan</td><td>Site → <b>Developer → People</b></td></tr>
|
| 443 |
+
<tr><td>PayPal keys (advanced)</td><td>Supabase → <b>Edge Functions → Secrets</b></td></tr>
|
| 444 |
<tr><td>The project address and key</td><td>Supabase → <b>Project Settings → API</b>; site → <b>Developer → Supabase</b></td></tr>
|
| 445 |
<tr><td>Emails students receive</td><td>Supabase → <b>Authentication → Emails</b></td></tr>
|
| 446 |
<tr><td>Which address students see as the sender</td><td>Supabase → <b>Authentication → Emails → SMTP Settings</b></td></tr>
|
|
|
|
| 463 |
<tr><td>No developer console in the sidebar</td><td>You are signed in as a different email. Sign out, sign in as lucas.owen13@icloud.com.</td></tr>
|
| 464 |
<tr><td>"Supabase could not be reached"</td><td>Project URL or anon key pasted wrong. Developer → Supabase → paste again from Project Settings → API.</td></tr>
|
| 465 |
<tr><td>Plans page is empty</td><td>Step 2 did not run. Supabase → SQL Editor → paste the file → Run.</td></tr>
|
| 466 |
+
<tr><td>"This plan has no PayPal payment link yet"</td><td>Add the link to that plan in Developer → Plans, or you are in live mode with a test link.</td></tr>
|
| 467 |
<tr><td>Sign-up says "check your email" but nothing arrives</td><td>Confirmation is on and Supabase's built-in sender only reaches your own team. Connect Resend (last section), or turn Confirm email off in Authentication → Providers → Email.</td></tr>
|
| 468 |
</table>
|
| 469 |
</div>
|
js/admin.js
CHANGED
|
@@ -74,8 +74,8 @@ const BLANK_PLAN = {
|
|
| 74 |
cost_limit_cents: 0,
|
| 75 |
download_tier: 0,
|
| 76 |
byok: true,
|
| 77 |
-
|
| 78 |
-
|
| 79 |
active: true,
|
| 80 |
sort: 0
|
| 81 |
};
|
|
@@ -142,8 +142,8 @@ function PlanEditor({ plan, onDone }) {
|
|
| 142 |
<${Area} label="Features" hint="one per line" value=${features} onChange=${setFeatures} rows=${4} />
|
| 143 |
</div>
|
| 144 |
<div class="grid two" style=${{ marginTop: "10px" }}>
|
| 145 |
-
<${Text} label="
|
| 146 |
-
<${Text} label="
|
| 147 |
</div>
|
| 148 |
<div class="row wrap" style=${{ marginTop: "10px" }}>
|
| 149 |
<${Check} label="Published" checked=${draft.active} onChange=${(v) => set({ active: v })} />
|
|
@@ -360,21 +360,27 @@ function WordingTab() {
|
|
| 360 |
}
|
| 361 |
|
| 362 |
// ---------------------------------------------------------------------------
|
| 363 |
-
//
|
| 364 |
// ---------------------------------------------------------------------------
|
| 365 |
|
| 366 |
-
function
|
| 367 |
const cloud = useCloud();
|
| 368 |
-
const [
|
| 369 |
-
const [mode, setMode] = useState(cloud.settings.
|
| 370 |
-
const [
|
|
|
|
| 371 |
const [busy, setBusy] = useState(false);
|
| 372 |
const [saved, setSaved] = useState(false);
|
| 373 |
|
| 374 |
const save = async () => {
|
| 375 |
setBusy(true);
|
| 376 |
try {
|
| 377 |
-
await cloud.setSettings({
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 378 |
setSaved(true);
|
| 379 |
setTimeout(() => setSaved(false), 2000);
|
| 380 |
} catch (err) {
|
|
@@ -385,35 +391,33 @@ function StripeTab() {
|
|
| 385 |
|
| 386 |
return html`<div>
|
| 387 |
<div class="card">
|
| 388 |
-
<div class="section-title" style=${{ marginBottom: "10px" }}>
|
| 389 |
<div class="grid two">
|
| 390 |
-
<${
|
|
|
|
|
|
|
|
|
|
| 391 |
options=${[
|
| 392 |
-
{ value: "
|
| 393 |
-
{ value: "
|
| 394 |
]} />
|
| 395 |
-
<${Text} label="
|
| 396 |
</div>
|
| 397 |
-
${mode === "function"
|
| 398 |
-
? html`<div style=${{ marginTop: "10px" }}>
|
| 399 |
-
<${Text} label="Checkout function" hint="deployed in Supabase" value=${fn} onChange=${setFn} mono=${true} />
|
| 400 |
-
</div>`
|
| 401 |
-
: html`<div class="tiny faint" style=${{ marginTop: "10px", lineHeight: 1.6 }}>
|
| 402 |
-
Add a payment link to each plan in Plans. The link gets the buyer's account attached automatically, so a webhook can grant access.
|
| 403 |
-
</div>`}
|
| 404 |
<div class="row" style=${{ marginTop: "12px" }}>
|
| 405 |
<button class="btn primary small" onClick=${save} disabled=${busy}>${busy ? html`<span class="spin"></span>` : saved ? "Saved" : "Save payment settings"}</button>
|
| 406 |
</div>
|
| 407 |
</div>
|
| 408 |
|
| 409 |
<div class="card" style=${{ marginTop: "12px" }}>
|
| 410 |
-
<div class="section-title" style=${{ marginBottom: "8px" }}>Where the
|
| 411 |
<div class="tiny muted" style=${{ lineHeight: 1.7 }}>
|
| 412 |
-
Never in this page.
|
| 413 |
</div>
|
| 414 |
<div class="divider"></div>
|
| 415 |
<div class="tiny muted" style=${{ lineHeight: 1.7 }}>
|
| 416 |
-
|
|
|
|
|
|
|
| 417 |
</div>
|
| 418 |
</div>
|
| 419 |
</div>`;
|
|
@@ -509,7 +513,7 @@ function PeopleTab() {
|
|
| 509 |
<div class="card">
|
| 510 |
<div class="section-title" style=${{ marginBottom: "8px" }}>Give someone a plan</div>
|
| 511 |
<div class="tiny faint" style=${{ marginBottom: "10px", lineHeight: 1.55 }}>
|
| 512 |
-
For payments taken outside
|
| 513 |
</div>
|
| 514 |
<div class="grid two">
|
| 515 |
<${Text} label="Buyer's email" value=${email} onChange=${setEmail} placeholder="student@example.com" />
|
|
@@ -564,7 +568,7 @@ const TABS = [
|
|
| 564 |
{ id: "plans", label: "Plans" },
|
| 565 |
{ id: "models", label: "Models & keys" },
|
| 566 |
{ id: "wording", label: "Wording" },
|
| 567 |
-
{ id: "
|
| 568 |
{ id: "people", label: "People" },
|
| 569 |
{ id: "supabase", label: "Supabase" }
|
| 570 |
];
|
|
@@ -611,10 +615,11 @@ export function Developer() {
|
|
| 611 |
<div class="grid two" style=${{ marginTop: "12px" }}>
|
| 612 |
<div class="card">
|
| 613 |
<div class="section-title" style=${{ marginBottom: "8px" }}>Payments</div>
|
| 614 |
-
<div class="row between"><span class="tiny muted">Mode</span><span class="tiny mono">${cloud.settings.
|
| 615 |
-
<div class="row between" style=${{ marginTop: "6px" }}><span class="tiny muted">
|
| 616 |
-
<div class="row between" style=${{ marginTop: "6px" }}><span class="tiny muted">
|
| 617 |
-
<
|
|
|
|
| 618 |
</div>
|
| 619 |
<div class="card">
|
| 620 |
<div class="section-title" style=${{ marginBottom: "8px" }}>The page itself</div>
|
|
@@ -642,7 +647,7 @@ export function Developer() {
|
|
| 642 |
${tab === "plans" && html`<${PlansTab} />`}
|
| 643 |
${tab === "models" && html`<${ModelsTab} />`}
|
| 644 |
${tab === "wording" && html`<${WordingTab} />`}
|
| 645 |
-
${tab === "
|
| 646 |
${tab === "people" && html`<${PeopleTab} />`}
|
| 647 |
${tab === "supabase" && html`<${SupabaseTab} />`}
|
| 648 |
</div>
|
|
|
|
| 74 |
cost_limit_cents: 0,
|
| 75 |
download_tier: 0,
|
| 76 |
byok: true,
|
| 77 |
+
paypal_plan_id: "",
|
| 78 |
+
paypal_payment_link: "",
|
| 79 |
active: true,
|
| 80 |
sort: 0
|
| 81 |
};
|
|
|
|
| 142 |
<${Area} label="Features" hint="one per line" value=${features} onChange=${setFeatures} rows=${4} />
|
| 143 |
</div>
|
| 144 |
<div class="grid two" style=${{ marginTop: "10px" }}>
|
| 145 |
+
<${Text} label="PayPal billing plan ID" hint="optional · P-… · API mode" value=${draft.paypal_plan_id} onChange=${(v) => set({ paypal_plan_id: v })} mono=${true} />
|
| 146 |
+
<${Text} label="PayPal payment link" hint="for payment-link mode" value=${draft.paypal_payment_link} onChange=${(v) => set({ paypal_payment_link: v })} mono=${true} />
|
| 147 |
</div>
|
| 148 |
<div class="row wrap" style=${{ marginTop: "10px" }}>
|
| 149 |
<${Check} label="Published" checked=${draft.active} onChange=${(v) => set({ active: v })} />
|
|
|
|
| 360 |
}
|
| 361 |
|
| 362 |
// ---------------------------------------------------------------------------
|
| 363 |
+
// PayPal
|
| 364 |
// ---------------------------------------------------------------------------
|
| 365 |
|
| 366 |
+
function PayPalTab() {
|
| 367 |
const cloud = useCloud();
|
| 368 |
+
const [client, setClient] = useState(cloud.settings.paypal_client_id || "");
|
| 369 |
+
const [mode, setMode] = useState(cloud.settings.paypal_mode || "live");
|
| 370 |
+
const [checkout, setCheckout] = useState(cloud.settings.checkout_mode || "function");
|
| 371 |
+
const [fn, setFn] = useState(cloud.settings.checkout_function || "paypal-checkout");
|
| 372 |
const [busy, setBusy] = useState(false);
|
| 373 |
const [saved, setSaved] = useState(false);
|
| 374 |
|
| 375 |
const save = async () => {
|
| 376 |
setBusy(true);
|
| 377 |
try {
|
| 378 |
+
await cloud.setSettings({
|
| 379 |
+
paypal_client_id: client.trim(),
|
| 380 |
+
paypal_mode: mode,
|
| 381 |
+
checkout_mode: checkout,
|
| 382 |
+
checkout_function: fn.trim() || "paypal-checkout"
|
| 383 |
+
});
|
| 384 |
setSaved(true);
|
| 385 |
setTimeout(() => setSaved(false), 2000);
|
| 386 |
} catch (err) {
|
|
|
|
| 391 |
|
| 392 |
return html`<div>
|
| 393 |
<div class="card">
|
| 394 |
+
<div class="section-title" style=${{ marginBottom: "10px" }}>PayPal</div>
|
| 395 |
<div class="grid two">
|
| 396 |
+
<${Text} label="Client ID" hint="live or sandbox app" value=${client} onChange=${setClient} mono=${true} />
|
| 397 |
+
<${Select} label="PayPal mode" value=${mode} onChange=${setMode}
|
| 398 |
+
options=${[{ value: "live", label: "Live" }, { value: "sandbox", label: "Sandbox" }]} />
|
| 399 |
+
<${Select} label="Checkout mode" value=${checkout} onChange=${setCheckout}
|
| 400 |
options=${[
|
| 401 |
+
{ value: "function", label: "PayPal API · automatic access" },
|
| 402 |
+
{ value: "payment_links", label: "PayPal payment links · manual access" }
|
| 403 |
]} />
|
| 404 |
+
<${Text} label="Checkout function" hint="deployed in Supabase" value=${fn} onChange=${setFn} mono=${true} />
|
| 405 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 406 |
<div class="row" style=${{ marginTop: "12px" }}>
|
| 407 |
<button class="btn primary small" onClick=${save} disabled=${busy}>${busy ? html`<span class="spin"></span>` : saved ? "Saved" : "Save payment settings"}</button>
|
| 408 |
</div>
|
| 409 |
</div>
|
| 410 |
|
| 411 |
<div class="card" style=${{ marginTop: "12px" }}>
|
| 412 |
+
<div class="section-title" style=${{ marginBottom: "8px" }}>Where the secrets go</div>
|
| 413 |
<div class="tiny muted" style=${{ lineHeight: 1.7 }}>
|
| 414 |
+
Never in this page. Add <span class="mono">PAYPAL_CLIENT_ID</span>, <span class="mono">PAYPAL_CLIENT_SECRET</span> and <span class="mono">PAYPAL_WEBHOOK_ID</span> in Supabase → Edge Functions → Secrets, then deploy <span class="mono">paypal-checkout</span> and <span class="mono">paypal-webhook</span>. Point a PayPal webhook at <span class="mono">https://YOUR-PROJECT.supabase.co/functions/v1/paypal-webhook</span>. Steps are in <span class="mono">supabase/SETUP.md</span>.
|
| 415 |
</div>
|
| 416 |
<div class="divider"></div>
|
| 417 |
<div class="tiny muted" style=${{ lineHeight: 1.7 }}>
|
| 418 |
+
${checkout === "function"
|
| 419 |
+
? "Prices and intervals come from the plans table. PayPal billing plans are created automatically the first time someone subscribes."
|
| 420 |
+
: "Paste a PayPal payment link on each plan in Plans. The site sends buyers there, but payment links do not say who paid — grant access in People after each sale."}
|
| 421 |
</div>
|
| 422 |
</div>
|
| 423 |
</div>`;
|
|
|
|
| 513 |
<div class="card">
|
| 514 |
<div class="section-title" style=${{ marginBottom: "8px" }}>Give someone a plan</div>
|
| 515 |
<div class="tiny faint" style=${{ marginBottom: "10px", lineHeight: 1.55 }}>
|
| 516 |
+
For payments taken outside PayPal, or to fix a webhook that missed. The plan stays until you revoke it.
|
| 517 |
</div>
|
| 518 |
<div class="grid two">
|
| 519 |
<${Text} label="Buyer's email" value=${email} onChange=${setEmail} placeholder="student@example.com" />
|
|
|
|
| 568 |
{ id: "plans", label: "Plans" },
|
| 569 |
{ id: "models", label: "Models & keys" },
|
| 570 |
{ id: "wording", label: "Wording" },
|
| 571 |
+
{ id: "paypal", label: "PayPal" },
|
| 572 |
{ id: "people", label: "People" },
|
| 573 |
{ id: "supabase", label: "Supabase" }
|
| 574 |
];
|
|
|
|
| 615 |
<div class="grid two" style=${{ marginTop: "12px" }}>
|
| 616 |
<div class="card">
|
| 617 |
<div class="section-title" style=${{ marginBottom: "8px" }}>Payments</div>
|
| 618 |
+
<div class="row between"><span class="tiny muted">Mode</span><span class="tiny mono">${cloud.settings.paypal_mode}</span></div>
|
| 619 |
+
<div class="row between" style=${{ marginTop: "6px" }}><span class="tiny muted">Checkout</span><span class="tiny mono">${cloud.settings.checkout_mode}</span></div>
|
| 620 |
+
<div class="row between" style=${{ marginTop: "6px" }}><span class="tiny muted">Client ID</span><span class="tiny mono">${cloud.settings.paypal_client_id ? "set" : "missing"}</span></div>
|
| 621 |
+
<div class="row between" style=${{ marginTop: "6px" }}><span class="tiny muted">Plans with a link or plan ID</span><span class="tiny mono">${cloud.plans.filter((p) => p.paypal_payment_link || p.paypal_plan_id).length}/${cloud.plans.length}</span></div>
|
| 622 |
+
<button class="btn small" style=${{ marginTop: "10px" }} onClick=${() => setTab("paypal")}>Open PayPal settings</button>
|
| 623 |
</div>
|
| 624 |
<div class="card">
|
| 625 |
<div class="section-title" style=${{ marginBottom: "8px" }}>The page itself</div>
|
|
|
|
| 647 |
${tab === "plans" && html`<${PlansTab} />`}
|
| 648 |
${tab === "models" && html`<${ModelsTab} />`}
|
| 649 |
${tab === "wording" && html`<${WordingTab} />`}
|
| 650 |
+
${tab === "paypal" && html`<${PayPalTab} />`}
|
| 651 |
${tab === "people" && html`<${PeopleTab} />`}
|
| 652 |
${tab === "supabase" && html`<${SupabaseTab} />`}
|
| 653 |
</div>
|
js/auth.js
CHANGED
|
@@ -260,7 +260,7 @@ export function Account({ onDone }) {
|
|
| 260 |
<div class="row between wrap">
|
| 261 |
<div style=${{ maxWidth: "520px" }}>
|
| 262 |
<div style=${{ fontWeight: 600 }}>Developer console</div>
|
| 263 |
-
<div class="tiny faint" style=${{ marginTop: "3px", lineHeight: 1.55 }}>Plans and prices,
|
| 264 |
</div>
|
| 265 |
<a class="btn primary small" href="#/developer">Open developer console</a>
|
| 266 |
</div>
|
|
|
|
| 260 |
<div class="row between wrap">
|
| 261 |
<div style=${{ maxWidth: "520px" }}>
|
| 262 |
<div style=${{ fontWeight: 600 }}>Developer console</div>
|
| 263 |
+
<div class="tiny faint" style=${{ marginTop: "3px", lineHeight: 1.55 }}>Plans and prices, PayPal, models and keys, page wording, and who has access.</div>
|
| 264 |
</div>
|
| 265 |
<a class="btn primary small" href="#/developer">Open developer console</a>
|
| 266 |
</div>
|
js/cloud.js
CHANGED
|
@@ -94,8 +94,8 @@ export const DEFAULT_PLANS = [
|
|
| 94 |
cost_limit_cents: 0,
|
| 95 |
download_tier: 1,
|
| 96 |
byok: true,
|
| 97 |
-
|
| 98 |
-
|
| 99 |
active: true,
|
| 100 |
sort: 1
|
| 101 |
},
|
|
@@ -116,8 +116,8 @@ export const DEFAULT_PLANS = [
|
|
| 116 |
cost_limit_cents: 0,
|
| 117 |
download_tier: 4,
|
| 118 |
byok: true,
|
| 119 |
-
|
| 120 |
-
|
| 121 |
active: true,
|
| 122 |
sort: 2
|
| 123 |
},
|
|
@@ -137,8 +137,8 @@ export const DEFAULT_PLANS = [
|
|
| 137 |
cost_limit_cents: 600,
|
| 138 |
download_tier: 4,
|
| 139 |
byok: true,
|
| 140 |
-
|
| 141 |
-
|
| 142 |
active: true,
|
| 143 |
sort: 3
|
| 144 |
},
|
|
@@ -158,8 +158,8 @@ export const DEFAULT_PLANS = [
|
|
| 158 |
cost_limit_cents: 500,
|
| 159 |
download_tier: 0,
|
| 160 |
byok: true,
|
| 161 |
-
|
| 162 |
-
|
| 163 |
active: true,
|
| 164 |
sort: 4
|
| 165 |
},
|
|
@@ -179,8 +179,8 @@ export const DEFAULT_PLANS = [
|
|
| 179 |
cost_limit_cents: 120,
|
| 180 |
download_tier: 2,
|
| 181 |
byok: true,
|
| 182 |
-
|
| 183 |
-
|
| 184 |
active: true,
|
| 185 |
sort: 5
|
| 186 |
},
|
|
@@ -200,8 +200,8 @@ export const DEFAULT_PLANS = [
|
|
| 200 |
cost_limit_cents: 400,
|
| 201 |
download_tier: 3,
|
| 202 |
byok: true,
|
| 203 |
-
|
| 204 |
-
|
| 205 |
active: true,
|
| 206 |
sort: 6
|
| 207 |
},
|
|
@@ -221,8 +221,8 @@ export const DEFAULT_PLANS = [
|
|
| 221 |
cost_limit_cents: 1000,
|
| 222 |
download_tier: 4,
|
| 223 |
byok: true,
|
| 224 |
-
|
| 225 |
-
|
| 226 |
active: true,
|
| 227 |
sort: 7
|
| 228 |
}
|
|
@@ -315,9 +315,10 @@ export const DEFAULT_MODELS = [
|
|
| 315 |
];
|
| 316 |
|
| 317 |
export const DEFAULT_SETTINGS = {
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
|
|
|
|
| 321 |
currency: "GBP",
|
| 322 |
support_email: DEVELOPER_EMAIL
|
| 323 |
};
|
|
@@ -773,24 +774,36 @@ export function CloudProvider({ children }) {
|
|
| 773 |
if (!chosen) throw new Error("Pick a plan first.");
|
| 774 |
if (!user) throw new Error("Sign in first, so the purchase can be attached to your account.");
|
| 775 |
const settings = config.ready ? cloud.settings : preview.settings;
|
| 776 |
-
if (settings.
|
| 777 |
-
if (!chosen.
|
| 778 |
-
|
| 779 |
-
|
| 780 |
-
|
| 781 |
-
window.location.href = url.toString();
|
| 782 |
return { redirect: true };
|
| 783 |
}
|
| 784 |
-
|
|
|
|
| 785 |
const { data, error: err } = await client.functions.invoke(fn, {
|
| 786 |
body: { plan_id: chosen.id, origin: window.location.origin }
|
| 787 |
});
|
| 788 |
-
if (err)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 789 |
if (data && data.url) {
|
| 790 |
window.location.href = data.url;
|
| 791 |
return { redirect: true };
|
| 792 |
}
|
| 793 |
-
|
|
|
|
| 794 |
},
|
| 795 |
[user, client, config.ready, cloud.settings, preview.settings]
|
| 796 |
);
|
|
|
|
| 94 |
cost_limit_cents: 0,
|
| 95 |
download_tier: 1,
|
| 96 |
byok: true,
|
| 97 |
+
paypal_plan_id: "",
|
| 98 |
+
paypal_payment_link: "",
|
| 99 |
active: true,
|
| 100 |
sort: 1
|
| 101 |
},
|
|
|
|
| 116 |
cost_limit_cents: 0,
|
| 117 |
download_tier: 4,
|
| 118 |
byok: true,
|
| 119 |
+
paypal_plan_id: "",
|
| 120 |
+
paypal_payment_link: "",
|
| 121 |
active: true,
|
| 122 |
sort: 2
|
| 123 |
},
|
|
|
|
| 137 |
cost_limit_cents: 600,
|
| 138 |
download_tier: 4,
|
| 139 |
byok: true,
|
| 140 |
+
paypal_plan_id: "",
|
| 141 |
+
paypal_payment_link: "",
|
| 142 |
active: true,
|
| 143 |
sort: 3
|
| 144 |
},
|
|
|
|
| 158 |
cost_limit_cents: 500,
|
| 159 |
download_tier: 0,
|
| 160 |
byok: true,
|
| 161 |
+
paypal_plan_id: "",
|
| 162 |
+
paypal_payment_link: "",
|
| 163 |
active: true,
|
| 164 |
sort: 4
|
| 165 |
},
|
|
|
|
| 179 |
cost_limit_cents: 120,
|
| 180 |
download_tier: 2,
|
| 181 |
byok: true,
|
| 182 |
+
paypal_plan_id: "",
|
| 183 |
+
paypal_payment_link: "",
|
| 184 |
active: true,
|
| 185 |
sort: 5
|
| 186 |
},
|
|
|
|
| 200 |
cost_limit_cents: 400,
|
| 201 |
download_tier: 3,
|
| 202 |
byok: true,
|
| 203 |
+
paypal_plan_id: "",
|
| 204 |
+
paypal_payment_link: "",
|
| 205 |
active: true,
|
| 206 |
sort: 6
|
| 207 |
},
|
|
|
|
| 221 |
cost_limit_cents: 1000,
|
| 222 |
download_tier: 4,
|
| 223 |
byok: true,
|
| 224 |
+
paypal_plan_id: "",
|
| 225 |
+
paypal_payment_link: "",
|
| 226 |
active: true,
|
| 227 |
sort: 7
|
| 228 |
}
|
|
|
|
| 315 |
];
|
| 316 |
|
| 317 |
export const DEFAULT_SETTINGS = {
|
| 318 |
+
paypal_client_id: "",
|
| 319 |
+
paypal_mode: "live",
|
| 320 |
+
checkout_mode: "function",
|
| 321 |
+
checkout_function: "paypal-checkout",
|
| 322 |
currency: "GBP",
|
| 323 |
support_email: DEVELOPER_EMAIL
|
| 324 |
};
|
|
|
|
| 774 |
if (!chosen) throw new Error("Pick a plan first.");
|
| 775 |
if (!user) throw new Error("Sign in first, so the purchase can be attached to your account.");
|
| 776 |
const settings = config.ready ? cloud.settings : preview.settings;
|
| 777 |
+
if ((settings.checkout_mode || "function") === "payment_links") {
|
| 778 |
+
if (!chosen.paypal_payment_link) {
|
| 779 |
+
throw new Error("This plan has no PayPal payment link yet. Add one in Developer → Plans.");
|
| 780 |
+
}
|
| 781 |
+
window.location.href = chosen.paypal_payment_link;
|
|
|
|
| 782 |
return { redirect: true };
|
| 783 |
}
|
| 784 |
+
if (!config.ready) throw new Error("PayPal checkout needs Supabase. Connect it in Developer settings.");
|
| 785 |
+
const fn = settings.checkout_function || "paypal-checkout";
|
| 786 |
const { data, error: err } = await client.functions.invoke(fn, {
|
| 787 |
body: { plan_id: chosen.id, origin: window.location.origin }
|
| 788 |
});
|
| 789 |
+
if (err) {
|
| 790 |
+
let message = err.message || "PayPal checkout could not start.";
|
| 791 |
+
if (err.context && typeof err.context.json === "function") {
|
| 792 |
+
try {
|
| 793 |
+
const body = await err.context.json();
|
| 794 |
+
if (body && body.message) message = body.message;
|
| 795 |
+
} catch {
|
| 796 |
+
// keep the original message
|
| 797 |
+
}
|
| 798 |
+
}
|
| 799 |
+
throw new Error(message);
|
| 800 |
+
}
|
| 801 |
if (data && data.url) {
|
| 802 |
window.location.href = data.url;
|
| 803 |
return { redirect: true };
|
| 804 |
}
|
| 805 |
+
if (data && data.message) throw new Error(data.message);
|
| 806 |
+
throw new Error("PayPal did not return an approval link.");
|
| 807 |
},
|
| 808 |
[user, client, config.ready, cloud.settings, preview.settings]
|
| 809 |
);
|
js/pricing.js
CHANGED
|
@@ -123,7 +123,7 @@ export function Pricing() {
|
|
| 123 |
|
| 124 |
${!cloud.configured &&
|
| 125 |
html`<div style=${{ marginTop: "14px" }}>
|
| 126 |
-
<${Notice} kind="warn">This is the preview shop front — connect Supabase and
|
| 127 |
</div>`}
|
| 128 |
${error && html`<div style=${{ marginTop: "14px" }}><${Notice} kind="error">${error}<//></div>`}
|
| 129 |
|
|
|
|
| 123 |
|
| 124 |
${!cloud.configured &&
|
| 125 |
html`<div style=${{ marginTop: "14px" }}>
|
| 126 |
+
<${Notice} kind="warn">This is the preview shop front — connect Supabase and PayPal in the developer console to take real payments.<//>
|
| 127 |
</div>`}
|
| 128 |
${error && html`<div style=${{ marginTop: "14px" }}><${Notice} kind="error">${error}<//></div>`}
|
| 129 |
|
schema.sql
CHANGED
|
@@ -25,9 +25,10 @@ $$;
|
|
| 25 |
|
| 26 |
create table if not exists public.explication_settings (
|
| 27 |
id integer primary key default 1 check (id = 1),
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
|
|
|
| 31 |
currency text not null default 'GBP',
|
| 32 |
support_email text not null default 'lucas.owen13@icloud.com',
|
| 33 |
updated_at timestamptz not null default now()
|
|
@@ -45,8 +46,8 @@ create table if not exists public.explication_plans (
|
|
| 45 |
cost_limit_cents integer not null default 0,
|
| 46 |
download_tier integer not null default 0,
|
| 47 |
byok boolean not null default true,
|
| 48 |
-
|
| 49 |
-
|
| 50 |
active boolean not null default true,
|
| 51 |
sort integer not null default 0,
|
| 52 |
updated_at timestamptz not null default now()
|
|
@@ -93,12 +94,45 @@ create table if not exists public.explication_entitlements (
|
|
| 93 |
granted_at timestamptz not null default now(),
|
| 94 |
expires_at timestamptz,
|
| 95 |
revoked boolean not null default false,
|
| 96 |
-
|
| 97 |
-
|
|
|
|
| 98 |
);
|
| 99 |
|
| 100 |
create index if not exists explication_entitlements_user on public.explication_entitlements (user_id);
|
| 101 |
create index if not exists explication_entitlements_email on public.explication_entitlements (lower(email));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
|
| 103 |
create table if not exists public.explication_usage (
|
| 104 |
id uuid primary key default gen_random_uuid(),
|
|
@@ -123,6 +157,9 @@ alter table public.explication_model_secrets enable row level security;
|
|
| 123 |
alter table public.explication_content enable row level security;
|
| 124 |
alter table public.explication_entitlements enable row level security;
|
| 125 |
alter table public.explication_usage enable row level security;
|
|
|
|
|
|
|
|
|
|
| 126 |
|
| 127 |
drop policy if exists settings_read on public.explication_settings;
|
| 128 |
create policy settings_read on public.explication_settings for select using (true);
|
|
|
|
| 25 |
|
| 26 |
create table if not exists public.explication_settings (
|
| 27 |
id integer primary key default 1 check (id = 1),
|
| 28 |
+
paypal_client_id text not null default '',
|
| 29 |
+
paypal_mode text not null default 'live' check (paypal_mode in ('live', 'sandbox')),
|
| 30 |
+
checkout_mode text not null default 'function' check (checkout_mode in ('payment_links', 'function')),
|
| 31 |
+
checkout_function text not null default 'paypal-checkout',
|
| 32 |
currency text not null default 'GBP',
|
| 33 |
support_email text not null default 'lucas.owen13@icloud.com',
|
| 34 |
updated_at timestamptz not null default now()
|
|
|
|
| 46 |
cost_limit_cents integer not null default 0,
|
| 47 |
download_tier integer not null default 0,
|
| 48 |
byok boolean not null default true,
|
| 49 |
+
paypal_plan_id text not null default '',
|
| 50 |
+
paypal_payment_link text not null default '',
|
| 51 |
active boolean not null default true,
|
| 52 |
sort integer not null default 0,
|
| 53 |
updated_at timestamptz not null default now()
|
|
|
|
| 94 |
granted_at timestamptz not null default now(),
|
| 95 |
expires_at timestamptz,
|
| 96 |
revoked boolean not null default false,
|
| 97 |
+
paypal_payer_id text,
|
| 98 |
+
paypal_subscription_id text,
|
| 99 |
+
paypal_order_id text
|
| 100 |
);
|
| 101 |
|
| 102 |
create index if not exists explication_entitlements_user on public.explication_entitlements (user_id);
|
| 103 |
create index if not exists explication_entitlements_email on public.explication_entitlements (lower(email));
|
| 104 |
+
create unique index if not exists explication_entitlements_paypal_order
|
| 105 |
+
on public.explication_entitlements (paypal_order_id) where paypal_order_id is not null;
|
| 106 |
+
|
| 107 |
+
-- PayPal checkout state. Only the service role (the Edge Functions) can read or
|
| 108 |
+
-- write these; they never reach a browser.
|
| 109 |
+
create table if not exists public.explication_paypal_orders (
|
| 110 |
+
order_id text primary key,
|
| 111 |
+
user_id uuid references auth.users(id) on delete cascade,
|
| 112 |
+
plan_id text references public.explication_plans(id) on delete set null,
|
| 113 |
+
origin text not null default '',
|
| 114 |
+
kind text not null default 'one_time',
|
| 115 |
+
subscription_id text,
|
| 116 |
+
status text not null default 'created',
|
| 117 |
+
created_at timestamptz not null default now()
|
| 118 |
+
);
|
| 119 |
+
|
| 120 |
+
create table if not exists public.explication_paypal_billing_plans (
|
| 121 |
+
plan_id text not null references public.explication_plans(id) on delete cascade,
|
| 122 |
+
mode text not null,
|
| 123 |
+
paypal_product_id text,
|
| 124 |
+
paypal_plan_id text not null,
|
| 125 |
+
updated_at timestamptz not null default now(),
|
| 126 |
+
primary key (plan_id, mode)
|
| 127 |
+
);
|
| 128 |
+
|
| 129 |
+
create table if not exists public.explication_paypal_payments (
|
| 130 |
+
sale_id text primary key,
|
| 131 |
+
subscription_id text,
|
| 132 |
+
plan_id text,
|
| 133 |
+
amount_cents integer not null default 0,
|
| 134 |
+
created_at timestamptz not null default now()
|
| 135 |
+
);
|
| 136 |
|
| 137 |
create table if not exists public.explication_usage (
|
| 138 |
id uuid primary key default gen_random_uuid(),
|
|
|
|
| 157 |
alter table public.explication_content enable row level security;
|
| 158 |
alter table public.explication_entitlements enable row level security;
|
| 159 |
alter table public.explication_usage enable row level security;
|
| 160 |
+
alter table public.explication_paypal_orders enable row level security;
|
| 161 |
+
alter table public.explication_paypal_billing_plans enable row level security;
|
| 162 |
+
alter table public.explication_paypal_payments enable row level security;
|
| 163 |
|
| 164 |
drop policy if exists settings_read on public.explication_settings;
|
| 165 |
create policy settings_read on public.explication_settings for select using (true);
|