openreceive-rails 0.4.10 → 0.4.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +33 -0
- data/README.md +33 -0
- data/app/models/open_receive_meta.rb +49 -28
- data/app/models/open_receive_payment.rb +107 -13
- data/lib/generators/openreceive/install/templates/initializer.rb +1 -1
- data/lib/openreceive/configuration.rb +3 -1
- data/lib/openreceive/generated/fulfillment_note.rb +17 -8
- data/lib/openreceive/rails/version.rb +1 -1
- data/lib/openreceive/reconcile.rb +108 -64
- data/lib/openreceive/reconcile_scan.rb +106 -0
- data/skills/debug-openreceive-payment/SKILL.md +1 -1
- data/skills/integrate-openreceive/SKILL.md +4 -3
- data/skills/integrate-openreceive/references/btcpay.md +67 -36
- data/skills/integrate-openreceive/references/django.md +291 -244
- data/skills/integrate-openreceive/references/fastapi.md +206 -155
- data/skills/integrate-openreceive/references/fastify.md +200 -147
- data/skills/integrate-openreceive/references/laravel.md +294 -234
- data/skills/integrate-openreceive/references/next.md +210 -162
- data/skills/integrate-openreceive/references/node.md +188 -138
- data/skills/integrate-openreceive/references/php.md +248 -193
- data/skills/integrate-openreceive/references/rails.md +262 -218
- data/skills/integrate-openreceive/references/woocommerce.md +68 -51
- metadata +6 -5
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# OpenReceive agent directions (Next.js)
|
|
2
2
|
|
|
3
|
-
These directions describe OpenReceive 0.4.
|
|
3
|
+
These directions describe OpenReceive 0.4.13.
|
|
4
4
|
|
|
5
5
|
Add OpenReceive to a Next.js App Router application — the app you are already
|
|
6
6
|
working in. You do not need a copy of the OpenReceive source: the packages are
|
|
@@ -34,64 +34,90 @@ The one required credential is a receive-only NWC code (Nostr Wallet Connect):
|
|
|
34
34
|
a string from the merchant's wallet that can create invoices and read their
|
|
35
35
|
status, and cannot spend. A swap provider (an "LSC" code) optionally lets the
|
|
36
36
|
payer send USDT, USDC, ETH or SOL instead, converted into that same
|
|
37
|
-
Lightning payment.
|
|
37
|
+
Lightning payment. Step 0 collects those credentials from the user; you write three hooks — `authorize`, `amountFor`,
|
|
38
38
|
`onPaid`;
|
|
39
39
|
OpenReceive supplies invoices, polling, settlement and the checkout UI. It never
|
|
40
40
|
owns orders, users, prices, or fulfillment.
|
|
41
41
|
|
|
42
|
-
## Step 0 —
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
42
|
+
## Step 0 — ask for the two codes, one question at a time
|
|
43
|
+
|
|
44
|
+
Before anything else, look at one file: the project's `.env.local`, if it exists.
|
|
45
|
+
Read it only far enough to see whether `NWC_URI` and `LSC_URI_PRIMARY` are
|
|
46
|
+
there and non-empty, and never print the values. A code that is already
|
|
47
|
+
set is not asked for again; if both are set, skip to step 5
|
|
48
|
+
(making the server load the file), then the quickstart.
|
|
49
|
+
|
|
50
|
+
Otherwise your next action is a question to the user. Do not install packages,
|
|
51
|
+
edit the app, write `.env.example`, or search anywhere else before asking
|
|
52
|
+
it. Do not read deploy config (compose files, Vercel or platform secrets), Docker containers, or process environments, and never run
|
|
53
|
+
`printenv`. A new shop has neither code yet: hunting for one burns the turn and
|
|
54
|
+
can leak other secrets into the transcript.
|
|
55
|
+
|
|
56
|
+
Two server-only URIs are needed before the quickstart:
|
|
57
|
+
|
|
58
|
+
- `NWC_URI` — a receive-only Nostr Wallet Connect code,
|
|
59
|
+
`nostr+walletconnect://…`. Required for Bitcoin.
|
|
60
|
+
- `LSC_URI_PRIMARY` — a Lightning Swap Connect URI,
|
|
61
|
+
`lightning+swapconnect://…`. Required for USDT, USDC, ETH and SOL. Skip it
|
|
62
|
+
only when the user says they want Bitcoin alone.
|
|
63
|
+
|
|
64
|
+
The user never edits an environment file. They paste each code into the chat;
|
|
65
|
+
you store it. Ask one question per message.
|
|
66
|
+
|
|
67
|
+
1. **First message — the NWC code, and nothing else.** Ask for it and walk them
|
|
68
|
+
through getting it:
|
|
69
|
+
|
|
70
|
+
> To receive payments I need a receive-only wallet code. In Rizful: open
|
|
71
|
+
> the menu, tap NWC, choose Receive-only NWC code, and tap Copy
|
|
72
|
+
> (https://openreceive.org/get_a_nwc_code_to_receive_payments). If you would
|
|
73
|
+
> rather run your own wallet, Alby Hub works too: Connections → Add
|
|
74
|
+
> Connection → Read Only. Paste the code here and I will store it.
|
|
75
|
+
|
|
76
|
+
Do not mention `.env`, exports, or "tell me when it's set".
|
|
77
|
+
2. **When they paste it.** If it does not start with `nostr+walletconnect://`,
|
|
78
|
+
ask them to copy the receive-only code again. Otherwise write
|
|
79
|
+
`NWC_URI=<paste>` into the project's `.env.local`, creating the file if needed.
|
|
80
|
+
Make sure `.gitignore` covers `.env.local` (and `.dockerignore`, if the app has
|
|
81
|
+
one). Never echo the value, commit it, or put it in client code. Reply only
|
|
82
|
+
that it is saved, then ask the next question.
|
|
83
|
+
3. **Second message — swaps.** If the user already asked for stablecoins or
|
|
84
|
+
altcoins, skip the yes/no and go straight to the walkthrough. Otherwise ask
|
|
85
|
+
whether payers should also be able to pay with USDT, USDC, ETH or SOL. The
|
|
86
|
+
walkthrough:
|
|
87
|
+
|
|
88
|
+
> Go to https://lightning-swap.com, sign in for API keys, create a key, and
|
|
89
|
+
> copy the whole URI (https://openreceive.org/set_up_swap_provider). Paste
|
|
90
|
+
> it here and I will store it — or say "Bitcoin only" and I will continue
|
|
91
|
+
> without it.
|
|
92
|
+
|
|
93
|
+
Mention FixedFloat only if they already use it.
|
|
94
|
+
4. **When they paste it.** If it does not start with
|
|
95
|
+
`lightning+swapconnect://`, ask them to copy it again. Otherwise add
|
|
96
|
+
`LSC_URI_PRIMARY=<paste>` to the same `.env.local`, without echoing it. Swaps
|
|
97
|
+
are now on, so build the refund route back (the swap non-negotiable below) as
|
|
98
|
+
part of this integration. If they chose Bitcoin only, leave
|
|
99
|
+
`LSC_URI_PRIMARY` unset and skip that route.
|
|
100
|
+
5. **Make the server load the file — yourself.** Next loads
|
|
101
|
+
`.env.local` into `process.env` on its own: do not add `dotenv`, and never
|
|
102
|
+
give a credential a `NEXT_PUBLIC_` prefix, which inlines it into the browser
|
|
103
|
+
bundle. When the app is started with Docker Compose, give the service
|
|
104
|
+
`env_file: .env.local`. Restart the dev server after writing the file.
|
|
105
|
+
|
|
106
|
+
Do not invent placeholder URIs. Start the quickstart only once `NWC_URI` is
|
|
107
|
+
saved and `LSC_URI_PRIMARY` is saved or explicitly declined. The first boot
|
|
108
|
+
runs the receive-only preflight: if it reports spend methods such as
|
|
109
|
+
`pay_invoice`, remove `NWC_URI` from `.env.local` and ask for a receive-only code
|
|
110
|
+
again. Never set the spend-capable override to get past it.
|
|
111
|
+
|
|
112
|
+
### Upgrading an existing install
|
|
113
|
+
|
|
114
|
+
This is not the opening move of a new integration. When OpenReceive is ALREADY
|
|
115
|
+
installed here, `npx openreceive doctor` reports every credential as set/unset
|
|
116
|
+
(never the value) and probes the wallet. Check the installed
|
|
117
|
+
`@openreceive/node` and `@openreceive/browser` against the release named at the
|
|
118
|
+
top of this file: the headless display models below do not exist in older
|
|
119
|
+
versions, and the first tile click throws with nothing saying why. Upgrade
|
|
120
|
+
first.
|
|
95
121
|
|
|
96
122
|
Only then start the quickstart.
|
|
97
123
|
|
|
@@ -109,7 +135,7 @@ itself, and they hold for every integration.
|
|
|
109
135
|
payer-supplied amounts.
|
|
110
136
|
- `authorize` runs on every request, and the `resource` it receives is a CLAIM
|
|
111
137
|
the payer made, not proof. Read a framework session; never trust a body field.
|
|
112
|
-
- `onPaid` must be idempotent.
|
|
138
|
+
- `onPaid` must be idempotent. Its database fulfillment commits once per `reference` — your order id, one
|
|
113
139
|
per thing you fulfill, created before checkout, kept across retries, never
|
|
114
140
|
reused. A fresh id per page load lets one order be paid twice.
|
|
115
141
|
- Receive-only NWC is required; a spend-capable code fails closed at boot unless
|
|
@@ -290,6 +316,8 @@ enough; drop the `.md` for the same page a person would read.
|
|
|
290
316
|
Questions, or a problem with the library itself:
|
|
291
317
|
https://openreceive.org/contact
|
|
292
318
|
|
|
319
|
+
- https://openreceive.org/guides/payment-safety-upgrade.md — coordinated upgrades and reviewed repair of existing attempts
|
|
320
|
+
|
|
293
321
|
---
|
|
294
322
|
|
|
295
323
|
## The quickstart, in full
|
|
@@ -307,11 +335,11 @@ Next.js App Router + React. Requires Node ≥ 22 and Next ≥ 15 (App Router).
|
|
|
307
335
|
npm install @openreceive/next @openreceive/react
|
|
308
336
|
```
|
|
309
337
|
|
|
310
|
-
Install the adapter for your server and the UI package for your frontend
|
|
338
|
+
Install the adapter for your server and the UI package for your frontend. The
|
|
311
339
|
wallet client, HTTP handler, and contracts come along as dependencies. The
|
|
312
|
-
`openreceive` package is the CLI
|
|
313
|
-
install.
|
|
314
|
-
|
|
340
|
+
`openreceive` package is only the CLI, and `npx openreceive …` below needs no
|
|
341
|
+
install. On a different stack, swap the two packages; the rest of this guide
|
|
342
|
+
stays the same.
|
|
315
343
|
|
|
316
344
|
| | Packages |
|
|
317
345
|
| -------- | ----------------------------------------------------------------------------------------------------------------------------- |
|
|
@@ -319,18 +347,21 @@ identical.
|
|
|
319
347
|
| Frontend | `@openreceive/react`, `@openreceive/vue`, `@openreceive/svelte`, `@openreceive/angular`, `@openreceive/elements` (plain HTML) |
|
|
320
348
|
|
|
321
349
|
Express: [quickstart-node.md](https://openreceive.org/guides/quickstart-node.md) · Fastify:
|
|
322
|
-
[quickstart-fastify.md](https://openreceive.org/guides/quickstart-fastify.md). This page is the Next.js one
|
|
323
|
-
|
|
324
|
-
`app.use`, a client component for the
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
350
|
+
[quickstart-fastify.md](https://openreceive.org/guides/quickstart-fastify.md). This page is the Next.js one.
|
|
351
|
+
An agent given the Express guide goes wrong on Next.js in three places: Next
|
|
352
|
+
needs no `dotenv`, no `app.use`, and it needs a client component for the
|
|
353
|
+
checkout.
|
|
354
|
+
|
|
355
|
+
On a fresh project, `create-next-app` scaffolds the App Router for you. You
|
|
356
|
+
need no env loader, because Next loads `.env.local` itself. Install your ORM
|
|
357
|
+
before step 2 (`npm install prisma @prisma/client` on the Prisma path).
|
|
358
|
+
`openreceive scaffold` emits files for the ORM you name, but it never installs
|
|
359
|
+
that ORM.
|
|
360
|
+
|
|
361
|
+
Some editor sandboxes run npm with `ignore-scripts`. That setting skips
|
|
362
|
+
Prisma's engine download and esbuild's binary postinstall. If a typecheck or
|
|
363
|
+
build fails only in such an environment, the environment is the cause, not
|
|
364
|
+
your code.
|
|
334
365
|
|
|
335
366
|
### 2. Migrate the payment tables
|
|
336
367
|
|
|
@@ -338,25 +369,25 @@ build that fails only there is environmental, not a code problem.
|
|
|
338
369
|
npx openreceive scaffold payments --orm prisma # or drizzle | typeorm | sequelize | knex
|
|
339
370
|
```
|
|
340
371
|
|
|
341
|
-
`openreceive scaffold payments`
|
|
342
|
-
|
|
372
|
+
`openreceive scaffold payments` writes one schema or migration file for your
|
|
373
|
+
ORM, plus a wiring guide. It never touches a database.
|
|
343
374
|
→ [openreceive scaffold payments](https://openreceive.org/guides/api-reference.md#openreceive-scaffold-payments)
|
|
344
375
|
|
|
345
|
-
Then run the
|
|
346
|
-
`npx prisma migrate dev`). OpenReceive
|
|
347
|
-
is nothing else to generate. Details:
|
|
376
|
+
Then run the generated migration the way you normally do (for example
|
|
377
|
+
`npx prisma migrate dev`). OpenReceive runs the tables' logic at runtime, so
|
|
378
|
+
there is nothing else to generate. Details:
|
|
348
379
|
[Payment storage](https://openreceive.org/guides/storage.md), [Node ORM recipes](https://openreceive.org/guides/node-orms.md).
|
|
349
380
|
|
|
350
|
-
No ORM?
|
|
351
|
-
|
|
352
|
-
same DDL once yourself
|
|
353
|
-
`@openreceive/http
|
|
381
|
+
No ORM? You can pass a bare driver handle (`pg`, `node:sqlite`,
|
|
382
|
+
`better-sqlite3`) as the `db` in step 4. The scaffold has no flavor for it.
|
|
383
|
+
Instead of scaffolding, run the same DDL once yourself, using
|
|
384
|
+
`paymentsSchemaSql(dialect)` from `@openreceive/http`.
|
|
354
385
|
|
|
355
386
|
### 3. Add wallet credentials
|
|
356
387
|
|
|
357
|
-
Create a server-only `.env.local
|
|
358
|
-
own
|
|
359
|
-
|
|
388
|
+
Create a server-only `.env.local`. Next loads it into `process.env` on its
|
|
389
|
+
own, so do **not** add `dotenv`. Never prefix these variables with
|
|
390
|
+
`NEXT_PUBLIC_`, because that would inline them into the browser bundle.
|
|
360
391
|
|
|
361
392
|
```dotenv
|
|
362
393
|
NWC_URI=
|
|
@@ -365,25 +396,28 @@ LSC_URI_BACKUP=
|
|
|
365
396
|
```
|
|
366
397
|
|
|
367
398
|
1. Get a receive-only NWC code from a compatible wallet
|
|
368
|
-
([get one here](https://openreceive.org/get_a_nwc_code_to_receive_payments))
|
|
369
|
-
|
|
370
|
-
2.
|
|
371
|
-
|
|
399
|
+
([get one here](https://openreceive.org/get_a_nwc_code_to_receive_payments)).
|
|
400
|
+
Put it in `NWC_URI`.
|
|
401
|
+
2. Optional: set up a [swap provider](https://openreceive.org/set_up_swap_provider).
|
|
402
|
+
Put its connection string in `LSC_URI_PRIMARY`, and a second one in
|
|
403
|
+
`LSC_URI_BACKUP` if you have one.
|
|
372
404
|
|
|
373
|
-
Never put these values in browser code. Your
|
|
374
|
-
|
|
375
|
-
receive-only code ([Security](https://openreceive.org/guides/security.md)).
|
|
405
|
+
Never put these values in browser code. Your app refuses to start if the NWC
|
|
406
|
+
code also advertises spend methods such as `pay_invoice`. Create a
|
|
407
|
+
receive-only code instead ([Security](https://openreceive.org/guides/security.md)).
|
|
376
408
|
|
|
377
|
-
In production supply the same variables through your host's secret manager
|
|
378
|
-
process environment
|
|
379
|
-
|
|
409
|
+
In production, supply the same variables through your host's secret manager
|
|
410
|
+
or process environment. `.env.local` is for development, and `create-next-app`
|
|
411
|
+
gitignores it. → [Environment variables](https://openreceive.org/guides/environment-variables.md).
|
|
380
412
|
|
|
381
413
|
### 4. Wire OpenReceive
|
|
382
414
|
|
|
383
|
-
One catch-all route file
|
|
384
|
-
builds the wallet client and the host and returns the `GET`/`POST` exports
|
|
385
|
-
App Router expects
|
|
386
|
-
|
|
415
|
+
One catch-all route file takes your hooks and a database handle. The adapter
|
|
416
|
+
builds the wallet client and the host, and returns the `GET`/`POST` exports
|
|
417
|
+
the App Router expects. There is no background reconciler, meaning no job that
|
|
418
|
+
checks pending payments on a timer. Settlement runs during normal requests
|
|
419
|
+
instead, through the durable reconcile gate. That is what makes it safe on
|
|
420
|
+
serverless hosts.
|
|
387
421
|
|
|
388
422
|
```ts
|
|
389
423
|
// app/openreceive/[...openreceive]/route.ts
|
|
@@ -451,15 +485,14 @@ export const { GET, POST } = openReceiveNextHandlers({
|
|
|
451
485
|
});
|
|
452
486
|
```
|
|
453
487
|
|
|
454
|
-
The route file is a **server module
|
|
455
|
-
reads `process.env`,
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
match.
|
|
488
|
+
The route file is a **server module**. It imports your database handle and
|
|
489
|
+
reads `process.env`, so no client component may import anything from it. The
|
|
490
|
+
default prefix is `/openreceive`, which is the directory the file sits in. If
|
|
491
|
+
you put the catch-all under another directory, pass a matching `prefix`.
|
|
459
492
|
|
|
460
|
-
|
|
461
|
-
client shared with a worker
|
|
462
|
-
module load
|
|
493
|
+
Sometimes the options are themselves async, such as a database opened lazily
|
|
494
|
+
or a wallet client shared with a worker. Then build the handlers per request
|
|
495
|
+
instead of at module load. The Buy a Button example does exactly this:
|
|
463
496
|
|
|
464
497
|
```ts
|
|
465
498
|
async function handle(request: Request): Promise<Response> {
|
|
@@ -480,35 +513,44 @@ where many payers share one IP. → [Rate limiting](https://openreceive.org/guid
|
|
|
480
513
|
|
|
481
514
|
An optional worker, `startNotificationWorker({ service, host })`, listens for
|
|
482
515
|
wallet payment notifications so settlement does not wait for the next page
|
|
483
|
-
load. It is a separate long-lived Node process, not a route
|
|
484
|
-
host, skip it and rely on the request-path settlement above.
|
|
516
|
+
load. It is a separate long-lived Node process, not a route. On a serverless
|
|
517
|
+
host, skip it and rely on the request-path settlement described above.
|
|
485
518
|
→ [startNotificationWorker](https://openreceive.org/guides/api-reference.md#startnotificationworker)
|
|
486
519
|
|
|
487
|
-
|
|
488
|
-
|
|
520
|
+
You can also compose the pieces yourself (`createOpenReceive` + `createHost`)
|
|
521
|
+
when you need a shared wallet client or a custom repository.
|
|
489
522
|
→ [createOpenReceive](https://openreceive.org/guides/api-reference.md#createopenreceive) ·
|
|
490
523
|
[createHost](https://openreceive.org/guides/api-reference.md#createhost)
|
|
491
524
|
|
|
492
|
-
Your app also needs an ordinary
|
|
493
|
-
|
|
494
|
-
the `reference`. OpenReceive never
|
|
525
|
+
Your app also needs an ordinary route that creates the order. It validates the
|
|
526
|
+
cart, computes the price with exact decimal math, and returns the order id.
|
|
527
|
+
The page passes that id as the `reference`. OpenReceive never takes a price
|
|
528
|
+
from payer input.
|
|
529
|
+
|
|
530
|
+
The `reference` is a string you choose, and it identifies what gets fulfilled.
|
|
531
|
+
Use your order id. Make it:
|
|
495
532
|
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
across retries,
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
533
|
+
- one per thing you fulfill,
|
|
534
|
+
- created before checkout,
|
|
535
|
+
- kept across retries,
|
|
536
|
+
- never reused.
|
|
537
|
+
|
|
538
|
+
OpenReceive never looks inside the `reference`, but it relies on it:
|
|
539
|
+
|
|
540
|
+
- `onPaid` commits fulfillment once per reference.
|
|
541
|
+
- A new checkout under a reference that already settled is refused with 409.
|
|
542
|
+
- A fresh id on every page load would let one order be paid twice.
|
|
502
543
|
|
|
503
544
|
Naming boundary: TypeScript APIs use camelCase fields (`paymentHash`,
|
|
504
|
-
`amountMsats`)
|
|
505
|
-
|
|
545
|
+
`amountMsats`). Everything on the wire is snake_case (`payment_hash`,
|
|
546
|
+
`amount_msats`). The wire means the mounted HTTP routes and the browser
|
|
547
|
+
snapshots.
|
|
506
548
|
|
|
507
549
|
### 5. Render checkout
|
|
508
550
|
|
|
509
551
|
`<Checkout>` polls and holds state, so it is a **client component**. Put it in
|
|
510
|
-
a file that starts with `"use client"
|
|
511
|
-
same module
|
|
552
|
+
a file that starts with `"use client"`, and import the stylesheet from that
|
|
553
|
+
same module. The page that renders it can stay a server component.
|
|
512
554
|
|
|
513
555
|
```tsx
|
|
514
556
|
// app/checkout/[reference]/order-checkout.tsx
|
|
@@ -537,53 +579,58 @@ export default async function CheckoutPage({
|
|
|
537
579
|
```
|
|
538
580
|
|
|
539
581
|
`/checkout/[reference]` is deliberately a page of its own rather than a modal
|
|
540
|
-
on the cart
|
|
541
|
-
from you
|
|
542
|
-
|
|
543
|
-
([Swap refunds](https://openreceive.org/guides/swap-refunds.md)).
|
|
544
|
-
|
|
545
|
-
|
|
582
|
+
on the cart. A payer with a swap deposit in flight has no account and no email
|
|
583
|
+
from you. This URL is the only thing that brings them back to their payment,
|
|
584
|
+
so it has to survive a reload and a bookmark
|
|
585
|
+
([Swap refunds](https://openreceive.org/guides/swap-refunds.md)).
|
|
586
|
+
|
|
587
|
+
Do not render the checkout for a reference the current session may not see.
|
|
588
|
+
The page can read the session and return 404 before it renders, and
|
|
589
|
+
`authorize` refuses the routes regardless.
|
|
546
590
|
|
|
547
591
|
The checkout renders, polls, and settles itself. The compiled `styles.css`
|
|
548
592
|
sheets (`@openreceive/react`, `@openreceive/elements`) are self-contained and
|
|
549
|
-
scoped: every rule applies only inside what OpenReceive renders.
|
|
550
|
-
`transpilePackages` entry
|
|
593
|
+
scoped: every rule applies only inside what OpenReceive renders. You need no
|
|
594
|
+
`transpilePackages` entry, because the packages ship plain ESM.
|
|
551
595
|
|
|
552
596
|
Serve the compiled `styles.css` without Tailwind processing: import it from
|
|
553
597
|
JavaScript (with a CSS-capable bundler) or use a plain `<link rel="stylesheet">`.
|
|
554
598
|
Do not `@import` it into the host Tailwind entry. Its zero-specificity rules
|
|
555
599
|
allow host styles to override checkout styles; scoping does not prevent that.
|
|
556
600
|
|
|
557
|
-
`<Checkout>` is complete as rendered
|
|
601
|
+
`<Checkout>` is complete as rendered. It already shows the `description` from
|
|
558
602
|
`amountFor` and the collapsed transaction-details panel. Do not build a custom
|
|
559
|
-
UI to
|
|
560
|
-
drop-in ([Checkout UX](https://openreceive.org/guides/checkout-ux.md)).
|
|
603
|
+
UI to show them. The display rules for them become your job only if you
|
|
604
|
+
replace the drop-in component ([Checkout UX](https://openreceive.org/guides/checkout-ux.md)).
|
|
561
605
|
|
|
562
|
-
Match the host page's theme
|
|
563
|
-
stored choice, then the system scheme. If this page
|
|
564
|
-
it
|
|
565
|
-
|
|
566
|
-
variables under `data-theme
|
|
567
|
-
the
|
|
606
|
+
Match the host page's theme. By default the checkout follows the payer's
|
|
607
|
+
stored choice, then the system color scheme. If this page always uses one
|
|
608
|
+
theme, lock it with `<Checkout theme="dark" … />`. On the custom element, set
|
|
609
|
+
the `theme` attribute. Locking the theme keeps a white card off a dark page.
|
|
610
|
+
CSS variables under `data-theme` style the checkout.
|
|
611
|
+
[Frontend checkout](https://openreceive.org/guides/frontend-checkout.md) lists the settings you can change.
|
|
568
612
|
|
|
569
613
|
Everything the checkout draws ships inside the JavaScript: the payment-method
|
|
570
|
-
icons, the wallet logos and the pay tutorials. There is no image file to copy
|
|
571
|
-
or serve and no asset option to set. Deploy your normal JavaScript and CSS
|
|
614
|
+
icons, the wallet logos, and the pay tutorials. There is no image file to copy
|
|
615
|
+
or serve, and no asset option to set. Deploy your normal JavaScript and CSS
|
|
572
616
|
build output, including any generated JavaScript chunks. Bundlers with code
|
|
573
|
-
splitting can
|
|
574
|
-
|
|
575
|
-
Content-Security-Policy has a strict `img-src`, allow `data:`
|
|
617
|
+
splitting can wait to load tutorial screenshots until a tutorial first opens.
|
|
618
|
+
Single-file builds, including the standalone checkout, include them from the
|
|
619
|
+
start. If your Content-Security-Policy has a strict `img-src`, allow `data:`
|
|
576
620
|
([Provider registry](https://openreceive.org/guides/provider-registry.md#assets)).
|
|
577
621
|
|
|
578
|
-
That is the whole loop
|
|
579
|
-
an invoice
|
|
622
|
+
That is the whole loop. Your server owns the price and the order. The payer
|
|
623
|
+
gets an invoice. `onPaid` runs inside the settlement transaction. If that
|
|
624
|
+
transaction rolls back, the callback may run again. For delivery to outside
|
|
625
|
+
systems, use an outbox in your app: record the message in the transaction and
|
|
626
|
+
send it after commit.
|
|
580
627
|
|
|
581
|
-
|
|
582
|
-
is Buy a Button
|
|
628
|
+
Buy a Button is a runnable illustration of this boundary
|
|
583
629
|
(`examples/buttons/server/nextjs-fullstack`).
|
|
584
|
-
It
|
|
585
|
-
|
|
586
|
-
|
|
630
|
+
It is not a template to copy models from. It has products, visitors, and
|
|
631
|
+
orders, and the three hooks are the only bridge to OpenReceive. Its shop
|
|
632
|
+
routes are three-line App Router wrappers, and `/checkout/[reference]` is the
|
|
633
|
+
resumable page. Map that shape onto the models in THIS app.
|
|
587
634
|
|
|
588
635
|
### 6. Verify
|
|
589
636
|
|
|
@@ -591,16 +638,17 @@ as the resumable page. Map that shape onto the models in THIS app.
|
|
|
591
638
|
npx openreceive doctor
|
|
592
639
|
```
|
|
593
640
|
|
|
594
|
-
`openreceive doctor` checks Node, `NWC_URI`, and swap-provider
|
|
595
|
-
|
|
596
|
-
`--db <file-or-url>` to confirm the migration ran
|
|
597
|
-
`--url http://localhost:3000` to confirm the routes are mounted
|
|
641
|
+
`openreceive doctor` checks Node, `NWC_URI`, and the swap-provider
|
|
642
|
+
configuration. It also probes the wallet relay to confirm the code is
|
|
643
|
+
receive-only. Add `--db <file-or-url>` to confirm the migration ran. Add
|
|
644
|
+
`--url http://localhost:3000` to confirm the routes are mounted. Every failing
|
|
598
645
|
line states its own fix.
|
|
599
646
|
→ [openreceive doctor](https://openreceive.org/guides/api-reference.md#openreceive-doctor)
|
|
600
647
|
|
|
601
|
-
Then open the checkout in a browser
|
|
602
|
-
wallet logos render
|
|
603
|
-
If an image is missing,
|
|
604
|
-
panel for failed JavaScript chunks.
|
|
605
|
-
complete build output. Do not add image routes
|
|
606
|
-
use registry `icon_path`
|
|
648
|
+
Then open the checkout in a browser. Confirm the payment-method icons and
|
|
649
|
+
wallet logos render. Open a wallet's pay tutorial to check its screenshots.
|
|
650
|
+
If an image is missing, look in the console for CSP violations and in the
|
|
651
|
+
Network panel for failed JavaScript chunks. To fix it, allow `data:` in
|
|
652
|
+
`img-src` and deploy the complete build output. Do not add image routes or
|
|
653
|
+
copy package source images. Do not use registry `icon_path` or tutorial
|
|
654
|
+
`path` keys as browser URLs.
|