Spaces:
Running

quantilimited commited on
Commit
0291469
·
verified ·
1 Parent(s): a3af7e9

Upload 3 files

Browse files
Files changed (3) hide show
  1. SETUP.html +25 -21
  2. js/cloud.js +21 -0
  3. js/pricing.js +51 -3
SETUP.html CHANGED
@@ -85,7 +85,7 @@
85
  <span class="badge">● Explication setup</span>
86
  <h1>From an empty folder to taking payments.</h1>
87
  <p class="lede">Ten screens for the website, then one for the iPhone app. Each tells you exactly where to click, what to copy and where to paste it. No terminal, no code, no guessing.</p>
88
- <div class="meta"><span><i class="dot"></i> About 20 minutes</span><span><i class="dot"></i> Free tiers are enough</span><span><i class="dot"></i> Test mode first, real money later</span></div>
89
  </div>
90
  </header>
91
 
@@ -274,8 +274,8 @@
274
  <div class="step-head">
275
  <div class="num">7</div>
276
  <div>
277
- <h2>Make a Stripe payment link for one plan</h2>
278
- <p class="why">This is the simple route: no keys, no webhooks. Stripe hosts the checkout page, the site just sends people there.</p>
279
  </div>
280
  </div>
281
  <div class="body">
@@ -283,25 +283,25 @@
283
  <div class="chrome"><i></i><i></i><i></i><span class="url">dashboard.stripe.com → Products</span></div>
284
  <div class="pane">
285
  <div class="rail">
286
- <div class="item on"><span class="ic">▦</span> Products</div>
287
- <div class="item"><span class="ic">↗</span> Payment links</div>
288
- <div class="item"><span class="ic">◍</span> Test mode</div>
289
  </div>
290
  <div class="canvas">
291
- <h4>Add a product</h4>
292
- <p>Name it like the plan. One price, then create the link.</p>
293
- <div class="field"><span><span class="lab">Name</span><code>Student</code></span></div>
294
- <div class="field"><span><span class="lab">Price</span><code>£4.00 · monthly · recurring</code></span><span class="pin">6</span></div>
295
- <div class="row"><button class="btn green">Create payment link</button><span class="pin">7</span></div>
296
  </div>
297
  </div>
298
  </div>
299
  <div class="do">
300
- <b>Do this:</b> in Stripe flip <b>Test mode</b> on (top right). Go to <b>Products → Add product</b>, name it <b>Student</b>, add a price of <b>£4.00</b>, <b>monthly</b>, recurring <span class="pin">6</span>. Save, then press <b>Create payment link</b> <span class="pin">7</span> and copy the link.
301
- On the site open <b>Developer → Plans → Edit</b> on Student, paste it into <b>Stripe payment link</b>, and save. Repeat for the other six — the table below has every name, price and type.
302
  </div>
303
  <table class="where">
304
- <tr><th>Product name</th><th>Price in Stripe</th><th>Type</th></tr>
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 +310,10 @@
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">Test mode and live mode have different links. Keep test links while you practise, then swap them for live ones before launch.</div>
 
 
 
314
  </div>
315
  </section>
316
 
@@ -319,7 +322,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, Stripe takes the money but the site does not hear about it automatically. You approve the buyer by hand — one click.</p>
323
  </div>
324
  </div>
325
  <div class="body">
@@ -334,8 +337,8 @@
334
  </div>
335
  </div>
336
  </div>
337
- <div class="do"><b>Do this:</b> buy your own plan with test card <code class="inline">4242 4242 4242 4242</code>, any future date, any CVC. Then on the site open <b>Developer → People</b>, type the buyer's email, pick the plan and press <b>Grant access</b> <span class="pin">8</span>. The plan shows on their Account page immediately.</div>
338
- <div class="warn">Want purchases to unlock themselves? That is the optional checkout-function route in <code class="inline">supabase/SETUP.md</code>, step 3. It needs five terminal commands. Everything works without it — you just approve each sale.</div>
339
  </div>
340
  </section>
341
 
@@ -441,7 +444,7 @@
441
  <div class="do">
442
  <b>Then just build it.</b> Double-click <code class="inline">Install on iPhone.command</code> in the project folder with the iPhone plugged in, unlocked and trusted. It builds, signs with your existing development profile and installs. In Xcode you can also open <code class="inline">Explication.xcodeproj</code>, pick the iPhone and press Run.
443
  </div>
444
- <div class="warn">Until the products exist in App Store Connect, the Plans screen says the App Store has none for this build — that is expected, not a bug. StoreKit shows Apple's local price once they are live. Website Stripe purchases and App Store purchases are separate: a plan bought on the website does not unlock in the app, and the other way round.</div>
445
  </div>
446
  </section>
447
 
@@ -524,7 +527,7 @@
524
  <tr><td>Prices, plan names, wording of a plan</td><td>Site → <b>Developer → Plans → Edit</b></td></tr>
525
  <tr><td>Any sentence on any page</td><td>Site → <b>Developer → Wording → edit mode</b>, then click the words</td></tr>
526
  <tr><td>Model keys and endpoints</td><td>Site → <b>Developer → Models &amp; keys</b></td></tr>
527
- <tr><td>Payment links</td><td>Site → <b>Developer → Plans</b> → Stripe payment link field</td></tr>
528
  <tr><td>Who has a plan</td><td>Site → <b>Developer → People</b></td></tr>
529
  <tr><td>Stripe keys (advanced)</td><td>Supabase → <b>Edge Functions → Secrets</b></td></tr>
530
  <tr><td>The project address and key</td><td>Supabase → <b>Project Settings → API</b>; site → <b>Developer → Supabase</b></td></tr>
@@ -550,7 +553,8 @@
550
  <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>
551
  <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>
552
  <tr><td>Plans page is empty</td><td>Step 2 did not run. Supabase → SQL Editor → paste the file → Run.</td></tr>
553
- <tr><td>"This plan has no Stripe 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>
 
554
  <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>
555
  <tr><td>Hugging Face copy has no styling or buttons</td><td>The <b>js</b> and <b>vendor</b> folders were flattened on upload. Delete those files in the Space and upload them again as folders.</td></tr>
556
  </table>
 
85
  <span class="badge">● Explication setup</span>
86
  <h1>From an empty folder to taking payments.</h1>
87
  <p class="lede">Ten screens for the website, then one for the iPhone app. Each tells you exactly where to click, what to copy and where to paste it. No terminal, no code, no guessing.</p>
88
+ <div class="meta"><span><i class="dot"></i> About 20 minutes</span><span><i class="dot"></i> Free tiers are enough</span><span><i class="dot"></i> Money straight to your bank</span></div>
89
  </div>
90
  </header>
91
 
 
274
  <div class="step-head">
275
  <div class="num">7</div>
276
  <div>
277
+ <h2>Take payments into your bank account</h2>
278
+ <p class="why">No Stripe, no card details, no fees. The buyer sends the money straight to your account and you switch their plan on. The account details live in Supabase secrets, never in the site's files.</p>
279
  </div>
280
  </div>
281
  <div class="body">
 
283
  <div class="chrome"><i></i><i></i><i></i><span class="url">dashboard.stripe.com → Products</span></div>
284
  <div class="pane">
285
  <div class="rail">
286
+ <div class="item"><span class="ic">ƒ</span> Functions</div>
287
+ <div class="item on"><span class="ic">⚿</span> Secrets</div>
288
+ <div class="item"><span class="ic">▦</span> Plans</div>
289
  </div>
290
  <div class="canvas">
291
+ <h4>Edge Function secrets</h4>
292
+ <p>Read only by the bank-transfer function.</p>
293
+ <div class="field"><span><span class="lab">BANK_SORT_CODE</span><code>••-••-••</code></span><span class="pin">6</span></div>
294
+ <div class="field"><span><span class="lab">BANK_ACCOUNT_NUMBER</span><code>••••••••</code></span></div>
295
+ <div class="field"><span><span class="lab">BANK_ACCOUNT_NAME</span><code>Lucas Owen</code></span><span class="pin">7</span></div>
296
  </div>
297
  </div>
298
  </div>
299
  <div class="do">
300
+ <b>Already done for you.</b> The <b>bank-transfer</b> function is deployed and the three secrets are set, so the shop works as it is. Nothing to paste into the site: the sort code and account number are not in any file a visitor can download.
301
+ <br><br><b>To change the account</b> <span class="pin">6</span>: Supabase → <b>Edge Functions → Secrets</b>, edit the value, save. To change the name on the payment panel <span class="pin">7</span>, edit <b>BANK_ACCOUNT_NAME</b> the same way.
302
  </div>
303
  <table class="where">
304
+ <tr><th>Plan</th><th>Amount to send</th><th>Type</th></tr>
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
  <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">The buyer only sees the account details after signing in and confirming their email, and only when they press a plan. The panel shows the amount, the sort code, the account number and a reference like <code class="inline">EX-4F2A9C31</code> — the reference is what lets you match a payment to a person.</div>
314
+ <div class="do">
315
+ <b>Stripe is still there if you ever want cards.</b> Developer → Stripe takes payment links or the <code class="inline">stripe-checkout</code> function, and <code class="inline">supabase/SETUP.md</code> has the keys. Leave it empty and the shop uses bank transfer.
316
+ </div>
317
  </div>
318
  </section>
319
 
 
322
  <div class="num">8</div>
323
  <div>
324
  <h2>Try it, then give yourself the plan</h2>
325
+ <p class="why">A bank transfer cannot tell the site anything, so you approve each buyer by hand — one click.</p>
326
  </div>
327
  </div>
328
  <div class="body">
 
337
  </div>
338
  </div>
339
  </div>
340
+ <div class="do"><b>Do this:</b> sign in, open <b>Pricing</b> and press a plan. The panel shows the amount, the reference and the account — exactly what a buyer sees. Then open <b>Developer → People</b>, type the buyer's email, pick the plan and press <b>Grant access</b> <span class="pin">8</span>. The plan shows on their Account page immediately.</div>
341
+ <div class="warn">Bank transfer is manual by design: the money arrives with the reference, and you match it to the person. Check the <code class="inline">EX-…</code> reference in your banking app, then grant. Automatic unlocking needs a card processor — that is the Stripe route in <code class="inline">supabase/SETUP.md</code>.</div>
342
  </div>
343
  </section>
344
 
 
444
  <div class="do">
445
  <b>Then just build it.</b> Double-click <code class="inline">Install on iPhone.command</code> in the project folder with the iPhone plugged in, unlocked and trusted. It builds, signs with your existing development profile and installs. In Xcode you can also open <code class="inline">Explication.xcodeproj</code>, pick the iPhone and press Run.
446
  </div>
447
+ <div class="warn">Until the products exist in App Store Connect, the Plans screen says the App Store has none for this build — that is expected, not a bug. StoreKit shows Apple's local price once they are live. Website bank-transfer purchases and App Store purchases are separate: a plan bought on the website does not unlock in the app, and the other way round.</div>
448
  </div>
449
  </section>
450
 
 
527
  <tr><td>Prices, plan names, wording of a plan</td><td>Site → <b>Developer → Plans → Edit</b></td></tr>
528
  <tr><td>Any sentence on any page</td><td>Site → <b>Developer → Wording → edit mode</b>, then click the words</td></tr>
529
  <tr><td>Model keys and endpoints</td><td>Site → <b>Developer → Models &amp; keys</b></td></tr>
530
+ <tr><td>The account payments go into</td><td>Supabase → <b>Edge Functions → Secrets</b> → <code class="inline">BANK_SORT_CODE</code>, <code class="inline">BANK_ACCOUNT_NUMBER</code>, <code class="inline">BANK_ACCOUNT_NAME</code></td></tr>
531
  <tr><td>Who has a plan</td><td>Site → <b>Developer → People</b></td></tr>
532
  <tr><td>Stripe keys (advanced)</td><td>Supabase → <b>Edge Functions → Secrets</b></td></tr>
533
  <tr><td>The project address and key</td><td>Supabase → <b>Project Settings → API</b>; site → <b>Developer → Supabase</b></td></tr>
 
553
  <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>
554
  <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>
555
  <tr><td>Plans page is empty</td><td>Step 2 did not run. Supabase → SQL Editor → paste the file → Run.</td></tr>
556
+ <tr><td>"The bank details could not be loaded"</td><td>The <b>bank-transfer</b> function is missing or its secrets are empty. Supabase → Edge Functions: check <b>bank-transfer</b> is deployed and the three <code class="inline">BANK_…</code> secrets are set.</td></tr>
557
+ <tr><td>"Confirm your email first"</td><td>The buyer signed up but has not opened the confirmation email. That is deliberate: the account details are only released to confirmed accounts.</td></tr>
558
  <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>
559
  <tr><td>Hugging Face copy has no styling or buttons</td><td>The <b>js</b> and <b>vendor</b> folders were flattened on upload. Delete those files in the Space and upload them again as folders.</td></tr>
560
  </table>
js/cloud.js CHANGED
@@ -768,6 +768,25 @@ export function CloudProvider({ children }) {
768
  [user, client, config.ready, cloud.settings, preview.settings]
769
  );
770
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
771
  const hostedChat = useCallback(
772
  async (model, messages, onToken) => {
773
  if (!config.ready) throw new Error("Hosted models need Supabase. Connect it in Developer settings.");
@@ -871,6 +890,7 @@ export function CloudProvider({ children }) {
871
  grantPlan,
872
  revokeGrant,
873
  startCheckout,
 
874
  hostedChat,
875
  refresh: () => refresh(client),
876
  canDownload: (tier) => Number(tier || 0) <= 1 || (!!plan && Number(plan.download_tier || 0) >= Number(tier || 0)),
@@ -915,6 +935,7 @@ export function CloudProvider({ children }) {
915
  grantPlan,
916
  revokeGrant,
917
  startCheckout,
 
918
  hostedChat,
919
  refresh
920
  ]
 
768
  [user, client, config.ready, cloud.settings, preview.settings]
769
  );
770
 
771
+ // The bank details never exist in this file. They live in Supabase secrets and
772
+ // are released by the bank-transfer function to a signed-in, confirmed account.
773
+ const startBankTransfer = useCallback(
774
+ async (chosen) => {
775
+ if (!chosen) throw new Error("Pick a plan first.");
776
+ if (!user) throw new Error("Sign in first, so the payment can be matched to your account.");
777
+ if (!config.ready) throw new Error("Payments need the published site, not a preview.");
778
+ const { data, error: err } = await client.functions.invoke("bank-transfer", {
779
+ body: { plan_id: chosen.id }
780
+ });
781
+ if (err) throw err;
782
+ if (!data || !data.accountNumber) {
783
+ throw new Error((data && data.message) || "The bank details could not be loaded.");
784
+ }
785
+ return data;
786
+ },
787
+ [user, client, config.ready]
788
+ );
789
+
790
  const hostedChat = useCallback(
791
  async (model, messages, onToken) => {
792
  if (!config.ready) throw new Error("Hosted models need Supabase. Connect it in Developer settings.");
 
890
  grantPlan,
891
  revokeGrant,
892
  startCheckout,
893
+ startBankTransfer,
894
  hostedChat,
895
  refresh: () => refresh(client),
896
  canDownload: (tier) => Number(tier || 0) <= 1 || (!!plan && Number(plan.download_tier || 0) >= Number(tier || 0)),
 
935
  grantPlan,
936
  revokeGrant,
937
  startCheckout,
938
+ startBankTransfer,
939
  hostedChat,
940
  refresh
941
  ]
js/pricing.js CHANGED
@@ -82,10 +82,54 @@ function Group({ title, note, plans, cloud, buy, busy }) {
82
  </div>`;
83
  }
84
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85
  export function Pricing() {
86
  const cloud = useCloud();
87
  const [busy, setBusy] = useState("");
88
  const [error, setError] = useState("");
 
89
 
90
  const plans = cloud.plans.filter((p) => p.active !== false).sort((a, b) => (a.sort || 0) - (b.sort || 0));
91
  const oneOff = plans.filter((p) => p.kind === "one_time");
@@ -98,10 +142,13 @@ export function Pricing() {
98
  return;
99
  }
100
  setBusy(plan.id);
 
101
  try {
102
- await cloud.startCheckout(plan);
 
103
  } catch (err) {
104
- setError(err && err.message ? err.message : "Checkout could not start.");
 
105
  setBusy("");
106
  }
107
  };
@@ -114,7 +161,7 @@ export function Pricing() {
114
  <${Copy} id="pricing.subtitle">Marking is free, forever. When you want the bigger models for the long essays, pick a pack once — or a membership you can leave whenever you like.</${Copy}>
115
  </p>
116
  <div class="price-chips">
117
- <span><${Icon} name="check" size=${12} /> No card to start</span>
118
  <span><${Icon} name="check" size=${12} /> One-off options</span>
119
  <span><${Icon} name="check" size=${12} /> Cancel in two taps</span>
120
  <span><${Icon} name="check" size=${12} /> Works offline</span>
@@ -126,6 +173,7 @@ export function Pricing() {
126
  <${Notice} kind="warn">This is the preview shop front — connect Supabase and Stripe in the developer console to take real payments.<//>
127
  </div>`}
128
  ${error && html`<div style=${{ marginTop: "14px" }}><${Notice} kind="error">${error}<//></div>`}
 
129
 
130
  <div class="free-strip">
131
  <div>
 
82
  </div>`;
83
  }
84
 
85
+ function TransferPanel({ transfer, onClose }) {
86
+ const [copied, setCopied] = useState(false);
87
+ const d = transfer.details;
88
+ const copy = () => {
89
+ const text = [
90
+ "Explication — " + d.planName,
91
+ "Amount: " + d.amount,
92
+ "Account name: " + d.accountName,
93
+ "Sort code: " + d.sortCode,
94
+ "Account number: " + d.accountNumber,
95
+ "Reference: " + d.reference
96
+ ].join("\n");
97
+ navigator.clipboard
98
+ .writeText(text)
99
+ .then(() => {
100
+ setCopied(true);
101
+ setTimeout(() => setCopied(false), 2000);
102
+ })
103
+ .catch(() => {});
104
+ };
105
+ const line = (label, value) => html`<div class="row between" style=${{ borderTop: "1px solid var(--hairline)", padding: "9px 0" }}>
106
+ <span class="tiny muted">${label}</span>
107
+ <span class="tiny mono" style=${{ fontWeight: 600 }}>${value}</span>
108
+ </div>`;
109
+ return html`<div class="card" style=${{ marginTop: "16px", borderColor: "var(--accent)" }}>
110
+ <div class="row between">
111
+ <div class="section-title">Pay ${d.amount} by bank transfer</div>
112
+ <button class="btn small ghost" onClick=${onClose}>Close</button>
113
+ </div>
114
+ <p class="tiny muted" style=${{ marginTop: "6px", maxWidth: "580px", lineHeight: 1.6 }}>
115
+ Send exactly ${d.amount} from your bank app, with the reference in the payment note. ${d.note} Your plan is switched on as soon as the payment lands.
116
+ </p>
117
+ ${line("Account name", d.accountName)}
118
+ ${line("Sort code", d.sortCode)}
119
+ ${line("Account number", d.accountNumber)}
120
+ ${line("Reference", d.reference)}
121
+ <div class="row" style=${{ marginTop: "10px" }}>
122
+ <button class="btn small primary" onClick=${copy}>${copied ? "Copied" : "Copy the details"}</button>
123
+ <span class="tiny faint">${d.planName}</span>
124
+ </div>
125
+ </div>`;
126
+ }
127
+
128
  export function Pricing() {
129
  const cloud = useCloud();
130
  const [busy, setBusy] = useState("");
131
  const [error, setError] = useState("");
132
+ const [transfer, setTransfer] = useState(null);
133
 
134
  const plans = cloud.plans.filter((p) => p.active !== false).sort((a, b) => (a.sort || 0) - (b.sort || 0));
135
  const oneOff = plans.filter((p) => p.kind === "one_time");
 
142
  return;
143
  }
144
  setBusy(plan.id);
145
+ setTransfer(null);
146
  try {
147
+ const details = await cloud.startBankTransfer(plan);
148
+ setTransfer({ plan, details });
149
  } catch (err) {
150
+ setError(err && err.message ? err.message : "The payment details could not be loaded.");
151
+ } finally {
152
  setBusy("");
153
  }
154
  };
 
161
  <${Copy} id="pricing.subtitle">Marking is free, forever. When you want the bigger models for the long essays, pick a pack once — or a membership you can leave whenever you like.</${Copy}>
162
  </p>
163
  <div class="price-chips">
164
+ <span><${Icon} name="check" size=${12} /> Bank transfer — no card</span>
165
  <span><${Icon} name="check" size=${12} /> One-off options</span>
166
  <span><${Icon} name="check" size=${12} /> Cancel in two taps</span>
167
  <span><${Icon} name="check" size=${12} /> Works offline</span>
 
173
  <${Notice} kind="warn">This is the preview shop front — connect Supabase and Stripe in the developer console to take real payments.<//>
174
  </div>`}
175
  ${error && html`<div style=${{ marginTop: "14px" }}><${Notice} kind="error">${error}<//></div>`}
176
+ ${transfer && html`<${TransferPanel} transfer=${transfer} onClose=${() => setTransfer(null)} />`}
177
 
178
  <div class="free-strip">
179
  <div>