openreceive 0.4.26 → 0.4.28

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.
Files changed (29) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +14 -0
  3. data/lib/openreceive/version.rb +1 -1
  4. data/skills/integrate-openreceive/SKILL.md +37 -5
  5. data/skills/integrate-openreceive/references/astro.md +653 -0
  6. data/skills/integrate-openreceive/references/bolt.md +580 -0
  7. data/skills/integrate-openreceive/references/btcpay.md +1 -1
  8. data/skills/integrate-openreceive/references/django.md +23 -2
  9. data/skills/integrate-openreceive/references/edd.md +407 -0
  10. data/skills/integrate-openreceive/references/fastapi.md +23 -2
  11. data/skills/integrate-openreceive/references/fastify.md +31 -6
  12. data/skills/integrate-openreceive/references/flask.md +23 -2
  13. data/skills/integrate-openreceive/references/fossbilling.md +433 -0
  14. data/skills/integrate-openreceive/references/laravel.md +1 -1
  15. data/skills/integrate-openreceive/references/lovable.md +6 -2
  16. data/skills/integrate-openreceive/references/medusa.md +468 -0
  17. data/skills/integrate-openreceive/references/mobile.md +492 -0
  18. data/skills/integrate-openreceive/references/nestjs.md +41 -16
  19. data/skills/integrate-openreceive/references/next.md +34 -7
  20. data/skills/integrate-openreceive/references/node.md +34 -7
  21. data/skills/integrate-openreceive/references/nuxt.md +606 -0
  22. data/skills/integrate-openreceive/references/paymenter.md +369 -0
  23. data/skills/integrate-openreceive/references/php.md +7 -4
  24. data/skills/integrate-openreceive/references/rails.md +14 -9
  25. data/skills/integrate-openreceive/references/react-router.md +617 -0
  26. data/skills/integrate-openreceive/references/sveltekit.md +650 -0
  27. data/skills/integrate-openreceive/references/tanstack-start.md +734 -0
  28. data/skills/integrate-openreceive/references/woocommerce.md +8 -6
  29. metadata +12 -1
@@ -0,0 +1,617 @@
1
+ This is the full file; follow it from Step 0.
2
+
3
+ # OpenReceive agent directions (React Router)
4
+
5
+ ```sh
6
+ # READ THIS FIRST: this file is 34 KB and a summary drops required steps. Download it whole:
7
+ curl -fsSL https://openreceive.org/agent-directions/react-router/full.md
8
+ # Skip the download only if you already have all of it: pasted, read from disk or fetched raw.
9
+ ```
10
+
11
+ **Step 0 in brief** (Step 0 below has the details):
12
+
13
+ - Before installing or editing anything, ask the user for a receive-only NWC code. One question per message.
14
+ - Next ask for the LSC code. If the user wants stablecoins, USDT, USDC, ETH, SOL or crypto, do not ask yes/no first.
15
+ - The user only pastes codes into this chat. Never ask them to edit .env or run a command to save one.
16
+ - Write each code into .env yourself, as Step 0 says. Never echo it or put it in a shell command.
17
+ - Do not suggest rotating or revoking a code because it was pasted here.
18
+ - Start the quickstart only once the NWC code is saved, and the LSC code is saved or the user said "Bitcoin only".
19
+
20
+ These directions describe OpenReceive 0.4.28.
21
+
22
+ Add OpenReceive to a React Router application in framework mode — the app
23
+ you are already working in, on Node. OpenReceive ships no React Router
24
+ package: the integration is one resource route that hands each request to
25
+ `@openreceive/http`. You do not need a copy of the OpenReceive source: the
26
+ packages are on npm, and the React Router recipe is appended to this file in
27
+ full as the quickstart, so you can do the whole integration without fetching
28
+ anything. Prefer the published packages and the handler they export — do not
29
+ reimplement wallet RPC, settlement, or pricing.
30
+
31
+ Do not clone the OpenReceive repository into this app, and do not copy a demo's
32
+ models (`ShopOrder`, a signed-cookie visitor, an in-memory catalog) over tables
33
+ that already exist. Find this application's order, product, and user models —
34
+ whatever they are actually named — and map the three hooks onto those.
35
+
36
+ Keep this application's frontend framework, authentication and database. Pick
37
+ the UI package that matches the frontend that is already here
38
+ (`@openreceive/react`, `/vue`, `/svelte`, `/angular`, or `/elements` for
39
+ plain HTML) — do not add React to a Vue app. Reuse the app's existing
40
+ session/auth in `authorize` and its existing database handle in `storage.db`.
41
+
42
+ ## What OpenReceive is
43
+
44
+ A payment library that runs inside YOUR server. It mounts as ONE resource
45
+ route (`app/routes/openreceive.ts`, registered as `openreceive/*` in
46
+ `app/routes.ts`, on Node) in the application you are editing, issues Lightning
47
+ invoices against a wallet the merchant already controls, and calls back into
48
+ your code when one settles. There is no OpenReceive account and no API key, and
49
+ OpenReceive never holds the funds — the sats land in the wallet the merchant
50
+ connected.
51
+
52
+ The one required credential is a receive-only NWC code (Nostr Wallet Connect):
53
+ a string from the merchant's wallet that can create invoices and read their
54
+ status, and cannot spend. A swap provider (an "LSC" code) optionally lets the
55
+ payer send USDT, USDC, ETH or SOL instead, converted into that same
56
+ Lightning payment. Step 0 collects those credentials from the user; you write three hooks — `authorize`, `amountFor`,
57
+ `onPaid`;
58
+ OpenReceive supplies invoices, polling, settlement and the checkout UI. It never
59
+ owns orders, users, prices, or fulfillment.
60
+
61
+ ## Step 0 — ask for the two codes, one question at a time
62
+
63
+ Before anything else, check one file: the project's `.env`, if it exists.
64
+ `grep -E '^(NWC_URI|LSC_URI_PRIMARY)=.' .env | cut -d= -f1` names the codes
65
+ it sets without printing them. Check with that, here and after each write,
66
+ not by reading the file, and never print the values. A code that is already
67
+ set is not asked for again; if both are set, skip to step 5 (making the
68
+ server load the file), then the quickstart.
69
+
70
+ On a hosted builder (v0, Vercel, Replit, Lovable), the user may say instead
71
+ that both codes are already set as the project's environment variables or
72
+ secrets. Believe them: do not ask for the codes, do not write `.env`, and
73
+ do not read or print the variables. Skip step 5's file loading: the platform already puts them in `process.env`. Do not add them to a compose file or any other deploy config
74
+ either: they already reach the app, and a line such as `NWC_URI: ${NWC_URI}`
75
+ replaces them with an empty value.
76
+
77
+ Otherwise your next action is a question to the user. Do not install packages,
78
+ edit the app, write `.env.example`, or search anywhere else before asking
79
+ it. Do not read deploy config (compose files, Vercel or platform secrets), Docker containers, or process environments, and never run
80
+ `printenv`. A new shop has neither code yet: hunting for one burns the turn and
81
+ can leak other secrets into the transcript.
82
+
83
+ Two server-only URIs are needed before the quickstart:
84
+
85
+ - `NWC_URI` — a receive-only Nostr Wallet Connect code,
86
+ `nostr+walletconnect://…`. Required for Bitcoin.
87
+ - `LSC_URI_PRIMARY` — a Lightning Swap Connect URI,
88
+ `lightning+swapconnect://…`. Required for USDT, USDC, ETH and SOL. Skip it
89
+ only when the user says they want Bitcoin alone.
90
+
91
+ The user never edits an environment file. They paste each code into the chat;
92
+ you store it. Ask one question per message.
93
+
94
+ 1. **First message — the NWC code, and nothing else.** Ask for it and walk them
95
+ through getting it:
96
+
97
+ > To receive payments I need a receive-only wallet code. In Rizful: open
98
+ > the menu, tap NWC, choose Receive-only NWC code, and tap Copy
99
+ > (https://openreceive.org/get_a_nwc_code_to_receive_payments). If you would
100
+ > rather run your own wallet, Alby Hub works too: Connections → Add
101
+ > Connection → Read Only. Paste the code here and I will store it.
102
+
103
+ Do not mention `.env`, exports, or "tell me when it's set".
104
+ 2. **When they paste it.** If it does not start with `nostr+walletconnect://`,
105
+ ask them to copy the receive-only code again. Otherwise write
106
+ `NWC_URI=<paste>` into the project's `.env` with your file-editing
107
+ tool, creating the file if needed. Never write it with a shell command
108
+ (`echo`, `printf`, a heredoc, `python -c`): the command line shows the
109
+ code. Make sure `.gitignore` covers `.env` (and `.dockerignore`, if
110
+ the app has one). Never echo the value, commit it, or put it in client
111
+ code. Reply only that it is saved, then ask the next question.
112
+ 3. **Second message — swaps.** If the user asked for stablecoins, USDT, USDC,
113
+ ETH, SOL, altcoins or "crypto" (as in "Bitcoin and stablecoin payments"),
114
+ this message IS the walkthrough below: send it as it is, and do not ask yes
115
+ or no first. Otherwise ask whether payers should also be able to pay with
116
+ USDT, USDC, ETH or SOL, then give the walkthrough. The walkthrough:
117
+
118
+ > Go to https://lightning-swap.com, sign in for API keys, create a key, and
119
+ > copy the whole URI (https://openreceive.org/set_up_swap_provider). Paste
120
+ > it here and I will store it — or say "Bitcoin only" and I will continue
121
+ > without it.
122
+
123
+ Mention FixedFloat only if they already use it.
124
+ 4. **When they paste it.** If it does not start with
125
+ `lightning+swapconnect://`, ask them to copy it again. Otherwise add
126
+ `LSC_URI_PRIMARY=<paste>` to the same `.env` with the file-editing
127
+ tool, never a shell command. Swaps are now on, so build the refund route
128
+ back (the swap non-negotiable below) as part of this integration. If they
129
+ chose Bitcoin only, leave `LSC_URI_PRIMARY` unset and skip that route.
130
+ 5. **Make the server load the file — yourself.** OpenReceive reads
131
+ `process.env`. `react-router dev` loads `.env` into it, but
132
+ `react-router-serve` does not: start the built server with
133
+ `node --env-file=.env node_modules/.bin/react-router-serve ./build/server/index.js`.
134
+ When the app is started with Docker Compose, give the service
135
+ `env_file: .env`. Never give a code a `VITE_` prefix: that puts it in the
136
+ browser bundle. Restart the server after writing the file.
137
+ Under Compose, recreate the container with `docker compose up -d`:
138
+ `docker compose restart` keeps its old environment.
139
+
140
+ Do not invent placeholder URIs. Start the quickstart only once `NWC_URI` is
141
+ saved and `LSC_URI_PRIMARY` is saved or explicitly declined. The first boot
142
+ runs the receive-only preflight: if it reports spend methods such as
143
+ `pay_invoice`, remove `NWC_URI` from `.env` and ask for a receive-only code
144
+ again. Never set the spend-capable override to get past it.
145
+
146
+ ### Upgrading an existing install
147
+
148
+ This is not the opening move of a new integration. When OpenReceive is ALREADY
149
+ installed here, `npx openreceive doctor` reports every credential as set/unset
150
+ (never the value) and probes the wallet. Check the installed
151
+ `@openreceive/node` and `@openreceive/browser` against the release named at the
152
+ top of this file: the headless display models below do not exist in older
153
+ versions, and the first tile click throws with nothing saying why. Upgrade
154
+ first.
155
+
156
+ Only then start the quickstart.
157
+
158
+ ## After the quickstart — hand over, then stop
159
+
160
+ The quickstart is done when
161
+ `npx openreceive doctor --db <file-or-url> --url <app url>` is clean and this
162
+ app serves the checkout page for one of its orders. Doctor names any failed
163
+ check and exits nonzero; fix it before going on.
164
+ Doctor reads `.env` itself. Never source it into a shell: the `&` in a
165
+ code splits the value and prints the pieces.
166
+
167
+ Give the user that checkout link. The browser check of that page
168
+ (payment-method icons, wallet logos, a pay tutorial) is theirs: name it in one
169
+ line of your closing message, and do not run it yourself.
170
+
171
+ You cannot pay the invoice: the code is receive-only. Do not pay, settle or
172
+ mark an order paid, and do not look for a way to (a wallet control port, a
173
+ test endpoint, another wallet). If the user wants a real settlement test, they
174
+ pay on that link from their own wallet, and `onPaid` marks the order paid.
175
+
176
+ Setup ends here. Your last message starts "Setup is finished" and has at most
177
+ five short lines (about 80 characters each): the link, the methods it offers,
178
+ and one line of what to look at. Send nothing after it. Do not list what
179
+ changed, copy out the quickstart's browser checklist, offer more work, or end
180
+ the message on a question.
181
+
182
+ - The link is to a real unpaid order. Keep that order; do not delete it.
183
+ - When this app's orders belong to a session or cookie, the user's browser
184
+ cannot open the order you made. Then the link is the shop's own page:
185
+ "Open <shop url> and click Buy: it opens the checkout." Do not explain order
186
+ ownership or mention your test order.
187
+ - Name the methods it offers: Bitcoin, plus USDT, USDC, ETH and SOL when
188
+ `LSC_URI_PRIMARY` is saved. Do not mention minimums, and never say a coin
189
+ will not work or will not be offered.
190
+
191
+ ## Non-negotiables
192
+
193
+ The quickstart below has the code. These are the rules it cannot state for
194
+ itself, and they hold for every integration.
195
+
196
+ - OpenReceive never owns orders, users, prices, or fulfillment. The section
197
+ below is how those tables sit next to the library — not a second order model,
198
+ and not a Prisma/Drizzle relation to `openreceive_payments`.
199
+ - Keep `NWC_URI` / `LSC_URI_*` server-only. Never put them in browser code,
200
+ logs, or assets.
201
+ - Do not suggest rotating, revoking or replacing a code because it was pasted
202
+ into this chat; that is the supported path.
203
+ - Work only in this application. Never read or run anything from another
204
+ project on this machine (its `node_modules`, tools or source), for any
205
+ reason. A browser and Playwright are not part of setup.
206
+ - Restart only this app's server, on the port it already uses: stop the
207
+ process you started, or the one listening on that port, by its pid (or
208
+ restart its Compose service). Never `pkill` or `killall` by name: that
209
+ stops other people's servers too. Start it the way this project already
210
+ does (its README, Procfile, compose file or package script), on its own
211
+ port, not a port you pick.
212
+ - Run commands where the app runs. When a compose file builds it, run its
213
+ package manager, generators, migrations and doctor inside that service
214
+ (`docker compose exec` or `run`), and rebuild the image after adding a
215
+ package. This machine's language version and database path are not the
216
+ app's.
217
+ - To check that the running app sees the codes, run doctor: it reports each
218
+ one as present or missing and never prints a value. Never print the
219
+ environment (`printenv`, `env`, `docker compose config`), even filtered to
220
+ names.
221
+ - The host owns the price. `amountFor` reads it from your own data; reject
222
+ payer-supplied amounts.
223
+ - `authorize` runs on every request, and the `resource` it receives is a CLAIM
224
+ the payer made, not proof. Read a framework session; never trust a body field.
225
+ - `onPaid` must be idempotent. Its database fulfillment commits once per `reference` — your order id, one
226
+ per thing you fulfill, created before checkout, kept across retries, never
227
+ reused. A fresh id per page load lets one order be paid twice.
228
+ - Receive-only NWC is required; a spend-capable code fails closed at boot unless
229
+ explicitly overridden.
230
+ - There is NO merchant-initiated refund of a settled Lightning payment, because
231
+ the wallet cannot spend. Swap refunds — a payer reclaiming a deposit that
232
+ never converted — are the only refund OpenReceive performs, and only from the
233
+ `refund_required` provider state. Do not build, promise, or imply a Lightning
234
+ refund path.
235
+ - IF YOU TURN SWAPS ON, BUILD THE ROUTE BACK. A deposit that arrives short or
236
+ late becomes `refund_required`, and the payer claims it on a SECOND VISIT,
237
+ after leaving your page to fetch an address from another wallet. Three things
238
+ must exist or that money is unreachable through your UI: a per-order URL your
239
+ server serves (`/checkout/:reference` — `syncUrl` on `<Checkout>`, `sync-url`
240
+ or `resumable` on `<openreceive-checkout>`), your own order-summary route to
241
+ restore the order from, and the ATTEMPT.
242
+ `/checkouts/prepare` returns no attempts, so a checkout rebuilt from the
243
+ reference alone opens on the method grid. Re-picking the same coin
244
+ (`POST /swaps`) re-serves the committed attempt — but only while it is live,
245
+ and the shadow invoice behind a swap lasts about half an hour, after which the
246
+ same click mints a NEW deposit address and the refund is off-screen. Keep the
247
+ `payment_hash` and reopen the attempt with `POST /swaps/status`, which has no
248
+ such window. On the drop-ins: `resumePaymentHash`, fed from `onState`, on
249
+ `<Checkout>`; the `resume-payment-hash` attribute, fed from the
250
+ `openreceive-state` event (`event.detail.state.payment_hash`), on
251
+ `<openreceive-checkout>`.
252
+ That visit can come hours later, and `authorize` must still know the payer:
253
+ a session that expired in between answers 403 and strands the deposit. On a
254
+ guest shop, tie the order to a long-lived signed cookie, or put a secret
255
+ per-order token in its URL that your page trades for that cookie.
256
+ https://openreceive.org/guides/swap-refunds.md
257
+ - Show the payer WHAT THEY ARE BUYING. Return an optional `description` beside
258
+ the price from `amountFor` and both drop-ins render it above the amount.
259
+ Without it the checkout is a QR and "$1.00" with no sign of what the dollar
260
+ is for.
261
+ - Show the payer the transaction record: `createTransactionDetails(...)` rows,
262
+ collapsed behind a caret, on the live checkout AND on the receipt. A payment
263
+ hash and a deposit txid are the only evidence a payer has that they paid you.
264
+ `<Checkout>` / `<openreceive-checkout>` already render this panel and the
265
+ `description` — these two rules cost you code only on a custom UI or your own
266
+ receipt page, never a reason to replace the drop-in. (It returns no rows
267
+ while the rail is `checkout_lock` — before the payer has chosen anything
268
+ there is no transaction — so render the caret only when the rows are
269
+ non-empty.)
270
+ - The handler lives in a `.server.ts` module, and the stack is built on the
271
+ first request, never at import, so the build never connects to the wallet.
272
+ The route is a resource route — a `loader` and an `action`, no default
273
+ export — so React Router returns its Responses untouched. It runs on Node
274
+ (`react-router-serve` or the app's own server), never an edge runtime.
275
+ - `authorize` gets the Web `request`: read the app's session from its cookie
276
+ header, as its loaders do (`getSession(request.headers.get("cookie"))`). A
277
+ loader sees no socket address, so `rateLimiting.ip` reads only a header
278
+ that your own reverse proxy sets and overwrites, such as `x-real-ip`; never
279
+ one a client can send. Without such a proxy the limit does not apply.
280
+ - `<Checkout>` comes from `@openreceive/react`, with
281
+ `@openreceive/react/styles.css` imported from the route module, on the
282
+ order's own page: its resumable URL.
283
+ - HTTP JSON is snake_case; TypeScript APIs are camelCase.
284
+ - Money is integers or decimal strings — never binary floats.
285
+
286
+ ## Your tables, not ours
287
+
288
+ `npx openreceive scaffold payments` emits `openreceive_payments` and
289
+ `openreceive_meta` for THIS application's database. That is the whole
290
+ persistence OpenReceive needs. It does not replace your orders, users, or
291
+ products, and you do not join them.
292
+
293
+ - **Find this app's models first.** They may be named `Order`, `Invoice`,
294
+ `Booking`, `Product`, `Variant`, `User`, `Account` — anything. Wire the hooks
295
+ to those. Do not generate a parallel `ShopOrder` / `ShopProduct` / `ShopUser`
296
+ stack.
297
+ - **The payable row's id is the `reference`.** Create it before checkout, keep
298
+ it across retries, never reuse it. Pass that id to `<Checkout>` /
299
+ `<openreceive-checkout>`. A fresh id per page load lets one order be paid
300
+ twice.
301
+ - **Products (or the catalog) are the price authority.** Order creation reads
302
+ live prices into the order (snapshot line items if this app has them).
303
+ `amountFor` reads only that order — never a payer-supplied amount, never a
304
+ live catalog lookup that could re-price a cart already placed. Return
305
+ `{ currency, value }` as a decimal STRING, plus a `description` of what they
306
+ are buying.
307
+ - **Users own the order; OpenReceive never sees them.** `authorize` uses the
308
+ same ownership check this app already uses on the order show / pay page —
309
+ `getSession(request.headers.get("cookie"))`, a cookie, whatever it is.
310
+ `resource.reference` is a claim the payer sent, not proof.
311
+ - **The order is unpaid or paid.** Do not copy `pending` / `expired` / `failed`
312
+ / `attention` onto it. Those are attempt statuses on `openreceive_payments`. An
313
+ expired invoice does not cancel the order; a later checkout may mint another
314
+ attempt. The library refuses a new checkout under a reference that already
315
+ settled (409).
316
+ - **A paid order's page says it is paid and shows no checkout.** Nothing is left
317
+ to pay, and a checkout cannot start a new payment for a paid order. Mount the
318
+ checkout only while the order is unpaid. When it settles on the page, update
319
+ the page's status line from `onSettled` on `<Checkout>`: `onPaid` has already
320
+ marked the order paid. Keep that checkout mounted, because it is the payer's
321
+ receipt.
322
+ - **Pass this app's `db` handle.** Do not add a Prisma/Drizzle relation from
323
+ Order to `openreceive_payments`, and do not implement `PaymentRepository`
324
+ unless no supported handle can reach this database. `reference` is not unique
325
+ (many attempts per order). Fulfillment is a guarded transition on YOUR order
326
+ row inside `onPaid` — `UPDATE … WHERE state = 'awaiting_payment'` (or this
327
+ app's equivalent) through the `query` the library hands you, on that same
328
+ settlement transaction, not a second connection from your ORM. Database writes
329
+ only in the hook; emails, jobs, and pushes after commit. Placeholder style is
330
+ the dialect you declared: `?` on sqlite and mysql, `$1` on postgres.
331
+
332
+ ## If you build your own checkout UI
333
+
334
+ The drop-ins (`<Checkout>`, `<openreceive-checkout>`) already obey all of this.
335
+ This list is the short form of https://openreceive.org/guides/checkout-ux.md, for a
336
+ UI built on `@openreceive/browser/headless`. Read that before writing
337
+ components.
338
+
339
+ - Check Bitcoin → Switch payment method → Bitcoin: the grid must hide the
340
+ Lightning invoice, then restore the same bolt11 without another mint.
341
+ - `createCheckoutController` is the engine. Do not hand-roll a poll loop.
342
+ - `createCheckoutStatusModel` for the status line. Do not draw a
343
+ Cart → Pay → Done stepper. Read the model's `phase`, not the snapshot's.
344
+ - `resolveWizardSelection` decides whether to ask "which network?". A
345
+ one-network asset starts the swap from the tile. Key `selectedAssetByGroup`
346
+ by group (`USDT`), valued by `pay_in_asset` (`USDT_TRON`).
347
+ - `createMethodGridDisplay` for tiles, including `limitMessage` so an
348
+ unavailable method says the minimum in the payer's currency.
349
+ - `createSwapDisplayModel` → `display.copyRows` for deposits: address, memo,
350
+ and the bare amount each get a copy row. Render `swap.networkWarning*` as
351
+ the model gives it.
352
+ - `swap.deposit_amount` is the only amount a payer is told to send. Never put
353
+ a fiat valuation of it (`swap.fee.pay_in_fiat`) next to a stablecoin amount:
354
+ "$50.03" under "50.05 USDC" reads as a typo, and the payer asks which one to
355
+ send. The one fiat figure on a USDT/USDC deposit panel is the cart total
356
+ (`payout_fiat`); express "you send" and the fee in the token. Use
357
+ `createSwapFeeBreakdown(fee, swap)` — with the swap, not the fee alone — and
358
+ it applies this for you; SOL and ETH keep a fiat breakdown.
359
+ - `createCheckoutSession` owns mint and swap start. To start swaps, pass its
360
+ `swap` option (`selection`, `prefix`, `fetch`) together. Without it
361
+ `startSwap` reports through `onError`.
362
+ - `createQrSvg` is async. Use `createQrSvgController` so you do not render
363
+ `[object Promise]`.
364
+ - `checkoutLabels` for every payer-facing string. Only write copy it lacks.
365
+ - `stageSwapRefund` then `confirmSwapRefund` — only the second submits.
366
+ Validate with `getSwapRefundFormError`. Treat `409` as a normal outcome.
367
+ - Pass `{ resumable: true }` to `createSwapDisplayModel` when the payer has
368
+ a URL they can come back to, and render `display.refundReturnLabel`.
369
+ Resume helpers (`createGuestCheckoutResume`, `createGuestOrderFetcher`)
370
+ are on `@openreceive/browser`, not `/headless`.
371
+ - A refund replaces the deposit panel. On `refund_required` also drop
372
+ "switch payment method".
373
+ - No "Open wallet" button on desktop.
374
+ - Wallet suggestions: `getPaymentWizardRoutes()` +
375
+ `createWizardRouteDisplays`. Lightning only. Logos are data URIs; tutorial
376
+ images load from a JavaScript chunk. For a custom headless UI, load it when
377
+ a tutorial opens and look up the returned table by the tutorial's `path`:
378
+
379
+ ```js
380
+ import { loadPayTutorialImages } from "@openreceive/browser/headless";
381
+
382
+ const images = await loadPayTutorialImages();
383
+ const src = images[tutorial.path]; // data URI for the selected tutorial
384
+ ```
385
+
386
+ Render `src` as the image source and update your UI after loading. Existing
387
+ display objects do not update: their `tutorial.image` stays `undefined` if
388
+ created before loading. Alternatively, await the loader, recreate the displays
389
+ with `createWizardRouteDisplays`, and render the new `tutorial.image`.
390
+ Show the caption while loading or if loading fails; never use an empty image
391
+ source. Deploy all JavaScript chunks and allow `data:` in CSP `img-src`.
392
+ For missing images, check CSP errors, failed chunks, and stale displays.
393
+ Registry paths are lookup keys; there is no asset option or image route.
394
+
395
+ ## More documentation
396
+
397
+ Fetch one when the moment comes. Each is raw markdown, so a plain GET is
398
+ enough; drop the `.md` for the same page a person would read.
399
+
400
+ - https://openreceive.org/guides/authorization.md — before you write `authorize`
401
+ - https://openreceive.org/guides/environment-variables.md — every variable, and what is deliberately not one
402
+ - https://openreceive.org/guides/storage.md — the payment tables and the attempt state machine
403
+ - https://openreceive.org/guides/supabase.md — when the database is Supabase: its pooler, its certificate, and locking the tables away from its Data API
404
+ - https://openreceive.org/guides/serverless.md — when the app runs serverless (Netlify, AWS Lambda, Cloud Run, Google AI Studio): pooled database URLs, timeouts, and why it needs no cron or worker
405
+ - https://openreceive.org/guides/node-orms.md — recipes for Prisma, Drizzle, Knex, TypeORM, Sequelize
406
+ - https://openreceive.org/guides/frontend-checkout.md — the drop-in's props, attributes and slots
407
+ - https://openreceive.org/guides/mobile-apps.md — when a mobile app takes the payment: the checkout page it opens, and what the App Store and Google Play allow
408
+ - https://openreceive.org/guides/checkout-ux.md — read before building any custom UI
409
+ - https://openreceive.org/guides/headless-checkout.md — the controller, the display models, refunds
410
+ - https://openreceive.org/guides/provider-registry.md — where the wallet logos and pay
411
+ tutorials come from: inside the JavaScript, nothing to serve. This is the page
412
+ that owns the image rule, not the summary in checkout-ux.md
413
+ - https://openreceive.org/guides/automated-swaps.md — only if `LSC_URI_PRIMARY` is set
414
+ - https://openreceive.org/guides/swap-refunds.md — the refund flow, and the route back to it. Read it before you turn swaps on
415
+ - https://openreceive.org/guides/lightning-swap-connect.md — what an `LSC_URI_*` code actually is
416
+ - https://openreceive.org/guides/price-feeds.md — where the fiat→sats rate comes from, and how to replace it
417
+ - https://openreceive.org/guides/host-testing.md — testing your three hooks without a live wallet or provider
418
+ - https://openreceive.org/guides/rate-limiting.md — before a public shop goes live
419
+ - https://openreceive.org/guides/security.md and https://openreceive.org/guides/deploying.md — before this goes anywhere real
420
+ - https://openreceive.org/guides/api-reference.md — every route, option and error code
421
+ - https://openreceive.org/guides/custom-checkout-route.md — advanced: replacing the shipped adapter's routes with your own
422
+ - https://openreceive.org/guides/react-material-ui-recipe.md — a worked custom UI on a component library
423
+ - https://openreceive.org/guides/quickstart-next.md — each hook explained step by step, on Next.js; they are the same here
424
+ - https://openreceive.org/guides.md — the index, if what you need is not above
425
+
426
+ Questions, or a problem with the library itself:
427
+ https://openreceive.org/contact
428
+
429
+ - https://openreceive.org/guides/payment-safety-upgrade.md — coordinated upgrades and reviewed repair of existing attempts
430
+
431
+ ---
432
+
433
+ ## The quickstart, in full
434
+
435
+ Inlined verbatim so this file needs no network access — follow it once Step 0
436
+ passes. The page it comes from is https://openreceive.org/guides/react-router-recipe.
437
+
438
+ ## React Router recipe
439
+
440
+ OpenReceive ships no React Router package. In React Router's framework mode
441
+ (formerly Remix), a resource route's `loader` and `action` take a
442
+ Web-standard `Request` and can return a `Response`, and so does
443
+ `@openreceive/http`, so the integration is the route below. Your server code
444
+ creates each Lightning invoice, the payment goes straight to your wallet, and
445
+ payment attempts are stored in your app's database. There is no OpenReceive
446
+ account and no background worker.
447
+
448
+ Optional swaps let customers pay with **USDT, USDC, SOL, and ETH**. A swap
449
+ provider you configure converts the payment to **BTC over Lightning**, and it
450
+ settles into the same wallet. Available assets and networks depend on the
451
+ provider.
452
+
453
+ This recipe was checked with `react-router` 8.4 (the default template, with
454
+ Tailwind) and `@openreceive/*` 0.4.25. The built app ran on Node in Docker
455
+ (`react-router-serve`), with Postgres and a test wallet on a public NWC
456
+ relay. In Chromium, the buyer's checkout page showed the Lightning invoice. A
457
+ stranger got 403 from the payment routes and 404 from the page, and a request
458
+ that named its own amount got 400. When the wallet marked the invoice paid,
459
+ the page showed it paid and `onPaid` marked the order paid.
460
+
461
+ ```sh
462
+ npm install @openreceive/http @openreceive/react pg
463
+ ```
464
+
465
+ ### Where it runs
466
+
467
+ On Node, with `react-router-serve` or your own Express server. The wallet
468
+ connection and your database driver need Node, so the route cannot run on an
469
+ edge runtime. On Vercel or Netlify, read
470
+ Bitcoin checkout on serverless hosts first. For
471
+ Cloudflare Workers, the [TanStack Start recipe](https://openreceive.org/guides/tanstack-start-recipe.md#where-it-runs)
472
+ explains what a Worker needs. This recipe was not run on those hosts.
473
+
474
+ ### The payment route
475
+
476
+ Keep the handler in a `.server.ts` module. React Router refuses to bundle one
477
+ into browser code:
478
+
479
+ ```ts
480
+ // app/lib/openreceive.server.ts
481
+ import { createStack, type Stack } from "@openreceive/http";
482
+ import { db } from "./db.server"; // your existing pg Pool
483
+ import { currentVisitor, findOrder } from "./orders.server"; // your own orders
484
+
485
+ let stack: Stack | undefined;
486
+
487
+ // Built on the first request, not at import, so the build never connects
488
+ // to the wallet.
489
+ function openReceive(): Stack {
490
+ stack ??= createStack({
491
+ wallet: { nwc: process.env.NWC_URI ?? "" },
492
+ storage: {
493
+ db,
494
+ // Runs once, inside the transaction that records the payment.
495
+ onPaid: async ({ reference, paidAt, query }) => {
496
+ await query(
497
+ "UPDATE orders SET state = 'paid', paid_at = $1 WHERE id = $2 AND state = 'awaiting_payment'",
498
+ [paidAt, reference],
499
+ );
500
+ },
501
+ },
502
+ // The price comes from the order row, never from the request.
503
+ amountFor: async (reference) => {
504
+ const order = await findOrder(reference);
505
+ return order?.state === "awaiting_payment"
506
+ ? { currency: order.currency, value: order.amount, description: order.title }
507
+ : null;
508
+ },
509
+ // Only the buyer may pay for their order.
510
+ authorize: async ({ request, resource }) => {
511
+ const order = resource.reference ? await findOrder(resource.reference) : undefined;
512
+ const visitor = await currentVisitor(request);
513
+ return Boolean(order && visitor && order.visitor === visitor);
514
+ },
515
+ // A loader sees no socket address. Read the header your reverse proxy
516
+ // sets and overwrites; never one a client can send through it.
517
+ rateLimiting: {
518
+ ip: ({ request }) => request.headers.get("x-real-ip") ?? undefined,
519
+ },
520
+ });
521
+ return stack;
522
+ }
523
+
524
+ export function handleOpenReceive(request: Request): Promise<Response> {
525
+ return openReceive().handler(request);
526
+ }
527
+ ```
528
+
529
+ ```ts
530
+ // app/routes/openreceive.ts
531
+ import { handleOpenReceive } from "~/lib/openreceive.server";
532
+ import type { Route } from "./+types/openreceive";
533
+
534
+ // A resource route: no component, so React Router returns these Responses as-is.
535
+ export const loader = ({ request }: Route.LoaderArgs) => handleOpenReceive(request);
536
+ export const action = ({ request }: Route.ActionArgs) => handleOpenReceive(request);
537
+ ```
538
+
539
+ ```ts
540
+ // app/routes.ts
541
+ import { type RouteConfig, index, route } from "@react-router/dev/routes";
542
+
543
+ export default [
544
+ index("routes/home.tsx"),
545
+ route("openreceive/*", "routes/openreceive.ts"), // every route under /openreceive/
546
+ route("checkout/:reference", "routes/checkout.tsx"),
547
+ ] satisfies RouteConfig;
548
+ ```
549
+
550
+ `authorize` sees the incoming request with its cookies, so check it with the
551
+ session your app already has. With `createCookieSessionStorage`,
552
+ `currentVisitor` is `(await getSession(request.headers.get("cookie"))).get("visitor")`.
553
+ The Next.js quickstart explains each hook.
554
+ They are the same here.
555
+
556
+ One stack serves the whole server process. A loader cannot see the
557
+ connection, so the client address comes from a header. Without a proxy that
558
+ sets it, the limit does not apply (Rate limiting).
559
+
560
+ ### Your database
561
+
562
+ `db` is a `pg` Pool, `node:sqlite` or `better-sqlite3`, or one of the
563
+ adapters in Node ORM recipes. With Drizzle, pass
564
+ the `pg` Pool underneath it.
565
+
566
+ Create OpenReceive's two tables with your migrations
567
+ (`npx openreceive scaffold payments --orm <your orm>`), or run
568
+ `paymentsSchemaSql("postgres")` from `@openreceive/http` once. It is
569
+ idempotent. See Payment storage.
570
+
571
+ ### The checkout page
572
+
573
+ ```tsx
574
+ // app/routes/checkout.tsx
575
+ import { Checkout } from "@openreceive/react";
576
+ import "@openreceive/react/styles.css";
577
+ import { data } from "react-router";
578
+ import { currentVisitor, findOrder } from "~/lib/orders.server";
579
+ import type { Route } from "./+types/checkout";
580
+
581
+ export async function loader({ params, request }: Route.LoaderArgs) {
582
+ const order = await findOrder(params.reference);
583
+ if (!order || order.visitor !== (await currentVisitor(request))) {
584
+ throw data("Not found", { status: 404 });
585
+ }
586
+ return { reference: order.id };
587
+ }
588
+
589
+ export default function OrderCheckout({ loaderData }: Route.ComponentProps) {
590
+ return <Checkout reference={loaderData.reference} prefix="/openreceive" />;
591
+ }
592
+ ```
593
+
594
+ Import `styles.css` from the route module, as above. Do not `@import` it
595
+ into your Tailwind entry (`app/app.css`); the checkout styles are compiled
596
+ already. The page renders on the server and starts the checkout in the
597
+ browser. The payer picks Bitcoin and gets the invoice. Keep it at the order's
598
+ own URL: a payer with a swap deposit in flight comes back to it
599
+ (Swap refunds).
600
+
601
+ ### Settings
602
+
603
+ - `NWC_URI`: a receive-only code from your wallet
604
+ ([get one](https://openreceive.org/get_a_nwc_code_to_receive_payments)).
605
+ - `DATABASE_URL`: your Postgres. On serverless hosts use the pooled URL.
606
+ - Optional: `LSC_URI_PRIMARY` for swaps
607
+ ([set one up](https://openreceive.org/set_up_swap_provider)), and
608
+ `LSC_URI_BACKUP`.
609
+
610
+ The route reads them from `process.env` when the first request arrives.
611
+ `react-router dev` loads `.env` into `process.env`. In production, set them
612
+ in the server's environment: `react-router-serve` does not read `.env`. Never
613
+ give them a `VITE_` prefix, which would put them in the browser bundle.
614
+
615
+ No worker or cron job is needed. Each request to the payment routes also
616
+ checks the wallet for settled invoices, through a lock in your database. A
617
+ payer who closes the tab is settled on the next request.