openreceive 0.4.11 → 0.4.14

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.
@@ -1,6 +1,6 @@
1
1
  # OpenReceive agent directions (Rails)
2
2
 
3
- These directions describe OpenReceive 0.4.11.
3
+ These directions describe OpenReceive 0.4.14.
4
4
 
5
5
  Add OpenReceive to a Rails application — the app you are already working in. You
6
6
  do not need a copy of the OpenReceive source: the gem is on RubyGems, the
@@ -33,69 +33,92 @@ The one required credential is a receive-only NWC code (Nostr Wallet Connect):
33
33
  a string from the merchant's wallet that can create invoices and read their
34
34
  status, and cannot spend. A swap provider (an "LSC" code) optionally lets the
35
35
  payer send USDT, USDC, ETH or SOL instead, converted into that same
36
- Lightning payment. You supply those credentials and three hooks — `config.authorize`,
36
+ Lightning payment. Step 0 collects those credentials from the user; you write three hooks — `config.authorize`,
37
37
  `config.amount_for`, `config.on_paid`;
38
38
  OpenReceive supplies invoices, polling, settlement and the checkout UI. It never
39
39
  owns orders, users, prices, or fulfillment.
40
40
 
41
- ## Step 0 — check the environment before you write code
42
-
43
- Do this before installing the gem or editing files.
44
-
45
- 1. Look for `NWC_URI` in this app's server environment — `.env`, Rails
46
- credentials, the deploy config, whatever this app already uses. If the app
47
- runs in a container the value is in none of those: ask the running process
48
- (`docker exec <container> printenv NWC_URI`), because finding the NAME in a
49
- compose file or `.kamal/secrets` proves nothing about the value. Never print
50
- or echo the value itself; only report whether it is set. Check for
51
- `LSC_URI_PRIMARY` in the same pass.
52
-
53
- If OpenReceive is already installed here, `bin/rails openreceive:doctor`
54
- answers this whole step in one command — every credential as set/unset, the
55
- engine mount, the three hooks, and the wallet preflight. It never prints a
56
- value.
57
- 2. If BOTH are already set — the common case in an existing app — say so and go
58
- straight to the quickstart. Steps 3 and 4 are for an environment that is
59
- missing one; do not stop to ask about altcoins that are already configured.
60
- If only `NWC_URI` is set, Bitcoin already works: continue, and raise the
61
- altcoin question at step 4 rather than blocking on it.
62
- 3. If `NWC_URI` is missing or empty, stop and tell the user exactly what to
63
- create:
64
-
65
- > OpenReceive cannot issue an invoice without a receive-only NWC code. Get
66
- > one at https://openreceive.org/get_a_nwc_code_to_receive_payments, then
67
- > put `NWC_URI=<the code>` in this app's server environment — for most apps
68
- > that is a `.env` file in the project root — and tell me when it's set.
69
-
70
- Wait for the user before wiring OpenReceive; do not invent a placeholder
71
- value. Waiting is not idleness: you may write `.env.example` with the
72
- variable NAMES only (`NWC_URI=`, `LSC_URI_PRIMARY=`) so the merchant has a
73
- file to copy, and keep building the parts of the host that do not touch
74
- OpenReceive — the order model, the cart, the routes. The stop guards the
75
- credential, not the rest of the app.
76
- 4. If `LSC_URI_PRIMARY` was not already set, ask the user: "Do you want to
77
- accept altcoins and stablecoins (USDT, USDC, ETH, SOL) as well as
78
- Bitcoin?"
79
-
80
- - Yes → send them to https://openreceive.org/set_up_swap_provider for a
81
- swap-provider (LSC) code, to set as `LSC_URI_PRIMARY` in the same server
82
- environment. Do NOT wait for it: no application code reads the value, so
83
- the integration is identical with or without it — the engine picks it up
84
- from the environment and swaps switch on. What a yes DOES change is the
85
- refund route back (the swap non-negotiable below): build it as part of
86
- this integration, not when the code arrives.
87
- - No → skip it. Bitcoin over Lightning works with `NWC_URI` alone, and you
88
- can add a swap provider later without changing application code.
89
- 5. Check the environment again and confirm `NWC_URI` is present.
90
- `LSC_URI_PRIMARY` may land later; swaps stay off until it does, and no code
91
- changes when it arrives.
92
- 6. If OpenReceive is ALREADY installed here, check the installed versions of
93
- `openreceive-rails` and `@openreceive/browser` against the release named at
94
- the top of this file. The headless display models below do not exist in
95
- older versions, and the first tile click throws with nothing saying why.
96
- Upgrade first — and if this app runs in containers, rebuild the images: the
97
- gems are baked into the image, so an in-place `bundle update` is undone by
98
- the next `compose up`.
41
+ ## Step 0 — ask for the two codes, one question at a time
42
+
43
+ Before anything else, look at one file: the project's `.env`, if it exists.
44
+ Read it only far enough to see whether `NWC_URI` and `LSC_URI_PRIMARY` are
45
+ there and non-empty, and never print the values. A code that is already
46
+ set is not asked for again; if both are set, skip to step 5
47
+ (making the server load the file), then the quickstart.
48
+
49
+ Otherwise your next action is a question to the user. Do not install the gem,
50
+ edit the app, write `.env.example`, or search anywhere else before asking
51
+ it. Do not read Rails credentials, deploy config (`config/deploy.yml`, `.kamal/secrets`, compose files), Docker containers, or process environments, and never run
52
+ `printenv`. A new shop has neither code yet: hunting for one burns the turn and
53
+ can leak other secrets into the transcript.
54
+
55
+ Two server-only URIs are needed before the quickstart:
56
+
57
+ - `NWC_URI` — a receive-only Nostr Wallet Connect code,
58
+ `nostr+walletconnect://…`. Required for Bitcoin.
59
+ - `LSC_URI_PRIMARY` — a Lightning Swap Connect URI,
60
+ `lightning+swapconnect://…`. Required for USDT, USDC, ETH and SOL. Skip it
61
+ only when the user says they want Bitcoin alone.
62
+
63
+ The user never edits an environment file. They paste each code into the chat;
64
+ you store it. Ask one question per message.
65
+
66
+ 1. **First message — the NWC code, and nothing else.** Ask for it and walk them
67
+ through getting it:
68
+
69
+ > To receive payments I need a receive-only wallet code. In Rizful: open
70
+ > the menu, tap NWC, choose Receive-only NWC code, and tap Copy
71
+ > (https://openreceive.org/get_a_nwc_code_to_receive_payments). If you would
72
+ > rather run your own wallet, Alby Hub works too: Connections → Add
73
+ > Connection → Read Only. Paste the code here and I will store it.
74
+
75
+ Do not mention `.env`, exports, or "tell me when it's set".
76
+ 2. **When they paste it.** If it does not start with `nostr+walletconnect://`,
77
+ ask them to copy the receive-only code again. Otherwise write
78
+ `NWC_URI=<paste>` into the project's `.env`, creating the file if needed.
79
+ Make sure `.gitignore` covers `.env` (and `.dockerignore`, if the app has
80
+ one). Never echo the value, commit it, or put it in client code. Reply only
81
+ that it is saved, then ask the next question.
82
+ 3. **Second message — swaps.** If the user already asked for stablecoins or
83
+ altcoins, skip the yes/no and go straight to the walkthrough. Otherwise ask
84
+ whether payers should also be able to pay with USDT, USDC, ETH or SOL. The
85
+ walkthrough:
86
+
87
+ > Go to https://lightning-swap.com, sign in for API keys, create a key, and
88
+ > copy the whole URI (https://openreceive.org/set_up_swap_provider). Paste
89
+ > it here and I will store it — or say "Bitcoin only" and I will continue
90
+ > without it.
91
+
92
+ Mention FixedFloat only if they already use it.
93
+ 4. **When they paste it.** If it does not start with
94
+ `lightning+swapconnect://`, ask them to copy it again. Otherwise add
95
+ `LSC_URI_PRIMARY=<paste>` to the same `.env`, without echoing it. Swaps
96
+ are now on, so build the refund route back (the swap non-negotiable below) as
97
+ part of this integration. If they chose Bitcoin only, leave
98
+ `LSC_URI_PRIMARY` unset and skip that route.
99
+ 5. **Make the server load the file — yourself.** Rails does not read
100
+ `.env` on its own. When the app is started with `bin/rails` or `bin/dev`,
101
+ add `dotenv-rails` to the Gemfile. When it is started with Docker Compose,
102
+ give the service `env_file: .env`. Restart the server after writing the
103
+ file; the values are read at boot.
104
+
105
+ Do not invent placeholder URIs. Start the quickstart only once `NWC_URI` is
106
+ saved and `LSC_URI_PRIMARY` is saved or explicitly declined. The first boot
107
+ runs the receive-only preflight: if it reports spend methods such as
108
+ `pay_invoice`, remove `NWC_URI` from `.env` and ask for a receive-only code
109
+ again. Never set the spend-capable override to get past it.
110
+
111
+ ### Upgrading an existing install
112
+
113
+ This is not the opening move of a new integration. When OpenReceive is ALREADY
114
+ installed here, `bin/rails openreceive:doctor` reports every credential as
115
+ set/unset (never the value), the engine mount, the three hooks, and the wallet
116
+ preflight. Check the installed `openreceive-rails` and `@openreceive/browser`
117
+ against the release named at the top of this file: the headless display models
118
+ below do not exist in older versions, and the first tile click throws with
119
+ nothing saying why. Upgrade first — and if this app runs in containers, rebuild
120
+ the images: the gems are baked into the image, so an in-place `bundle update`
121
+ is undone by the next `compose up`.
99
122
 
100
123
  Only then start the quickstart.
101
124
 
@@ -130,15 +153,19 @@ itself, and they hold for every integration.
130
153
  late becomes `refund_required`, and the payer claims it on a SECOND VISIT,
131
154
  after leaving your page to fetch an address from another wallet. Three things
132
155
  must exist or that money is unreachable through your UI: a per-order URL your
133
- server serves (`/checkout/:reference` — `syncUrl` on the drop-ins), your own
134
- order-summary route to restore the order from, and the ATTEMPT.
156
+ server serves (`/checkout/:reference` — `syncUrl` on `<Checkout>`, `sync-url`
157
+ or `resumable` on `<openreceive-checkout>`), your own order-summary route to
158
+ restore the order from, and the ATTEMPT.
135
159
  `/checkouts/prepare` returns no attempts, so a checkout rebuilt from the
136
160
  reference alone opens on the method grid. Re-picking the same coin
137
161
  (`POST /swaps`) re-serves the committed attempt — but only while it is live,
138
162
  and the shadow invoice behind a swap lasts about half an hour, after which the
139
163
  same click mints a NEW deposit address and the refund is off-screen. Keep the
140
164
  `payment_hash` and reopen the attempt with `POST /swaps/status`, which has no
141
- such window. https://openreceive.org/guides/swap-refunds.md
165
+ such window. On the drop-ins: `resumePaymentHash`, fed from `onState`, on
166
+ `<Checkout>`; the `resume-payment-hash` attribute, fed from the
167
+ `openreceive-state` event (`event.detail.state.payment_hash`), on
168
+ `<openreceive-checkout>`. https://openreceive.org/guides/swap-refunds.md
142
169
  - Show the payer WHAT THEY ARE BUYING. Return an optional `description` beside
143
170
  the price from `config.amount_for` and both drop-ins render it above the
144
171
  amount. Without it the checkout is a QR and "$1.00" with no sign of what the
@@ -304,15 +331,15 @@ Add the Rails engine gem to your `Gemfile`:
304
331
  gem "openreceive-rails"
305
332
  ```
306
333
 
307
- That is the whole install: `openreceive-rails` depends on `openreceive`,
308
- `openreceive-server` and `nwc-ruby`, so the default wallet client — built from
309
- `NWC_URI` — works with nothing else added. Hosts that bring their own NWC
310
- client set `config.nwc_client` instead.
334
+ That is the whole install. `openreceive-rails` depends on `openreceive`,
335
+ `openreceive-server` and `nwc-ruby`, so the default wallet client works with
336
+ nothing else added. It is built from `NWC_URI`. If your app brings its own NWC
337
+ client, set `config.nwc_client` instead.
311
338
 
312
- One native prerequisite: `nwc-ruby`'s `rbsecp256k1` builds libsecp256k1 from
313
- source, so minimal images (`ruby:3.3-slim`, fresh Docker builds) need the
314
- autotools or `bundle install` dies at `autoreconf: not found`. Before
315
- bundling:
339
+ There is one native prerequisite. `nwc-ruby` uses `rbsecp256k1`, which builds
340
+ libsecp256k1 from source. Minimal images (`ruby:3.3-slim`, fresh Docker builds)
341
+ need the autotools for that, or `bundle install` fails with
342
+ `autoreconf: not found`. Install them before bundling:
316
343
 
317
344
  ```sh
318
345
  apt-get install -y autoconf automake libtool build-essential pkg-config
@@ -327,34 +354,34 @@ bin/rails generate openreceive:install
327
354
  bin/rails db:migrate
328
355
  ```
329
356
 
330
- `openreceive:install` emits one migration for both engine tables, the
331
- initializer, and the engine mount. The migration adapts to the app's configured
332
- database adapter — PostgreSQL, SQLite, and MySQL (`mysql2`/`trilogy`) are
333
- supported.
357
+ The migration adapts to your app's database adapter. PostgreSQL, SQLite, and
358
+ MySQL (`mysql2`/`trilogy`) are supported.
334
359
  → [openreceive:install](https://openreceive.org/guides/api-reference.md#openreceiveinstall)
335
360
 
336
- The generator emits three things:
361
+ The `openreceive:install` generator emits three things:
337
362
 
338
- - `db/migrate/*_create_openreceive_tables.rb` — one migration creating both
339
- engine tables (`openreceive_payments` and `openreceive_meta`);
340
- - a simplified `config/initializers/openreceive.rb`;
341
- - the `OpenReceive::Engine` route mount at `/openreceive`.
363
+ - `db/migrate/*_create_openreceive_tables.rb`: one migration that creates both
364
+ engine tables (`openreceive_payments` and `openreceive_meta`).
365
+ - A simplified `config/initializers/openreceive.rb`.
366
+ - The `OpenReceive::Engine` route mount at `/openreceive`.
342
367
 
343
- The `OpenReceivePayment` model is engine-owned — no model file is generated.
344
- The engine owns the table's commit locking, write-once settlement, and
345
- reconciliation state machine. `reference` is indexed but not unique (a
346
- reference may have many historical attempts); `payment_hash` is globally unique.
368
+ The engine owns the `OpenReceivePayment` model, so no model file is generated.
369
+ The engine also owns the table's commit locking, write-once settlement, and
370
+ reconciliation state machine. `reference` is indexed but not unique, because
371
+ one reference may have many historical attempts. `payment_hash` is globally
372
+ unique.
347
373
 
348
374
  #### Fulfill exactly once
349
375
 
350
376
  Within OpenReceive's own settlement paths, `on_paid` runs at most once per
351
- reference: a second payment to a second invoice is recorded with
352
- `status_reason = "duplicate_settlement"` and never fulfills again.
377
+ reference. If a second invoice for the same reference is paid, OpenReceive
378
+ records that payment with `status_reason = "duplicate_settlement"` and does
379
+ not fulfill again.
353
380
 
354
- The one thing you own: **if anything other than OpenReceive can also fulfill
355
- an order** — an admin action, a second payment processor, a replayed job —
356
- those paths race each other, and `on_paid` must be idempotent. The generated
357
- initializer spells this out and shows the guarded transition:
381
+ One case is yours to handle. **If anything other than OpenReceive can also
382
+ fulfill an order**, such as an admin action, a second payment processor, or a
383
+ replayed job, those paths race each other. Then `on_paid` must be idempotent.
384
+ The generated initializer explains this and shows the guarded transition:
358
385
 
359
386
  ```ruby
360
387
  config.on_paid = lambda do |settlement|
@@ -369,19 +396,19 @@ config.on_paid = lambda do |settlement|
369
396
  end
370
397
  ```
371
398
 
372
- Delivery is at-least-once: `on_paid` runs inside the settlement transaction,
373
- and a raise rolls it back for the next pass to retry. Keep it to database
374
- writes on the order — an email or webhook sent from here would survive the
375
- rollback and go out again. The `state: "paid"` transition above is the flag;
376
- let your own job drain it after commit.
399
+ Delivery is at-least-once. `on_paid` runs inside the settlement transaction. If
400
+ it raises, the transaction rolls back and the next pass retries. So keep
401
+ `on_paid` to database writes on the order. An email or webhook sent from here
402
+ would survive the rollback and go out again. The `state: "paid"` transition
403
+ above is the flag. Let your own job drain it after commit.
377
404
 
378
- **`update_all` fires no Active Record callbacks.** That is the point — it is one
379
- conditional `UPDATE`, so the claim is atomic and there is no model code between
380
- the check and the write. It also means there is no `after_commit` to hang a
381
- post-commit side effect on, which is fine for a background job draining the flag
382
- and useless for a page that wants to know *now*. If you push settlement over
383
- Action Cable, or your model owns the transition through callbacks, take a row
384
- lock for the duration instead:
405
+ **`update_all` fires no Active Record callbacks.** That is intended. It runs one
406
+ conditional `UPDATE`, so the claim is atomic and no model code runs between the
407
+ check and the write. It also means there is no `after_commit` to attach a
408
+ post-commit side effect to. That is fine for a background job that drains the
409
+ flag. It does not help a page that needs to know right away. If you push
410
+ settlement over Action Cable, or your model owns the transition through
411
+ callbacks, take a row lock for the duration instead:
385
412
 
386
413
  ```ruby
387
414
  config.on_paid = lambda do |settlement|
@@ -391,52 +418,61 @@ config.on_paid = lambda do |settlement|
391
418
  end
392
419
  ```
393
420
 
394
- **Unlocking a download works the same way.** If what the payer bought is a
395
- file, do not unlock it in the browser: gate the download route on the paid
396
- order row — `Order.find_by(id: params[:id], user: current_user, state: "paid")`
397
- or a 404 — and serve the file only then. The `state: "paid"` written above is
398
- the unlock; the client never decides an order was fulfilled, it re-reads the
399
- row. Buy a Button's `ShopController#download` is this in twenty lines.
400
-
401
- Both shapes are idempotent, and both are correct. They differ only in whether
402
- your model layer gets to run: `update_all` skips it and is the right default;
403
- the row lock holds the row for the duration of the block and is what you want
404
- when the transition has to go through your model. The generated fulfillment note
405
- says the same thing — if your fulfillment is a read-modify-write that cannot be
406
- expressed as one conditional `UPDATE`, take the lock.
407
-
408
- Either way the rule above still holds: whatever the callback does must be
409
- database writes on the order. `after_commit` on the settlement transaction runs
410
- after OpenReceive's own commit, so an email enqueued there is as safe as one
411
- enqueued from a job draining the flag — and an email sent *inline* from
412
- `on_paid` is not, in either shape.
413
-
414
- A runnable illustration of this boundary — not a template to copy models from —
415
- is Buy a Button
416
- (`examples/buttons/server/rails`).
417
- It has products, visitors, and orders, with the three hooks as the only bridge.
418
- Map that shape onto the models in THIS app.
421
+ **Unlocking a download works the same way.** If the payer bought a file, do not
422
+ unlock it in the browser. Gate the download route on the paid order row, and
423
+ serve the file only if that row exists:
424
+ `Order.find_by(id: params[:id], user: current_user, state: "paid")`, or a 404
425
+ otherwise. The `state: "paid"` written above is the unlock. The client never
426
+ decides that an order was fulfilled. It re-reads the row. Buy a Button's
427
+ `ShopController#download` does this in twenty lines.
428
+
429
+ Both shapes are idempotent and correct. They differ only in whether your model
430
+ layer runs:
431
+
432
+ - `update_all` skips the model layer. It is the right default.
433
+ - The row lock holds the row for the duration of the block. Use it when the
434
+ transition has to go through your model.
435
+
436
+ The generated fulfillment note says the same thing. If your fulfillment is a
437
+ read-modify-write that one conditional `UPDATE` cannot express, take the lock.
438
+
439
+ Either way, the rule above still holds: the callback must only make database
440
+ writes on the order. `after_commit` on the settlement transaction runs after
441
+ OpenReceive's own commit. So an email enqueued there is as safe as one enqueued
442
+ from a job that drains the flag. An email sent *inline* from `on_paid` is not
443
+ safe, in either shape.
444
+
445
+ Buy a Button
446
+ (`examples/buttons/server/rails`)
447
+ is a runnable illustration of this boundary. It is not a template to copy
448
+ models from. It has products, visitors, and orders, and the three hooks are the
449
+ only bridge. Map that shape onto the models in THIS app.
419
450
 
420
451
  Supply the receive-only wallet connection as `ENV["NWC_URI"]`. Never put it in
421
452
  browser code, logs, or assets. Your application refuses to start when the code
422
- advertises spend methods such as `pay_invoice`; the explicit override is
423
- `config.allow_spend_capable_wallet = true` or
453
+ advertises spend methods such as `pay_invoice`. To override that explicitly,
454
+ set `config.allow_spend_capable_wallet = true` or
424
455
  `OPENRECEIVE_ALLOW_SPEND_CAPABLE_NWC=true` ([Security](https://openreceive.org/guides/security.md)).
425
456
 
426
- OpenReceive reads `ENV`; Rails does not load a `.env` file on its own.
427
- `dotenv-rails`, an exported shell environment, or your production secret
428
- manager has to put the values there first.
457
+ OpenReceive reads `ENV`. Rails does not load a `.env` file on its own, so
458
+ something has to put the values there first: `dotenv-rails`, an exported shell
459
+ environment, or your production secret manager.
429
460
  → [Environment variables](https://openreceive.org/guides/environment-variables.md).
430
461
 
431
462
  ### Configure the host hooks
432
463
 
433
464
  The initializer needs three things: authorization, the trusted price, and
434
- fulfillment. All three receive the `reference` — a string you choose, and the
435
- fulfillment identity: your order id, one per thing you fulfill, created before
436
- checkout, kept across retries, never reused. OpenReceive never looks inside
437
- it, but `on_paid` commits fulfillment once per reference, a new checkout under a reference
438
- that already settled is refused with 409, and a fresh id per page load lets
439
- one order be paid twice.
465
+ fulfillment. All three receive the `reference`. This is a string you choose,
466
+ and it is the fulfillment identity. Use your order id:
467
+
468
+ - one per thing you fulfill,
469
+ - created before checkout,
470
+ - kept across retries,
471
+ - never reused.
472
+
473
+ OpenReceive never looks inside it. But `on_paid` commits fulfillment once per
474
+ reference, and a new checkout under a reference that already settled is
475
+ refused with 409. A fresh id per page load would let one order be paid twice.
440
476
 
441
477
  ```ruby
442
478
  OpenReceive.configure do |config|
@@ -488,25 +524,27 @@ OpenReceive.configure do |config|
488
524
  end
489
525
  ```
490
526
 
491
- `OpenReceive.configure` sets the three host hooks; `on_paid` runs inside the
527
+ `OpenReceive.configure` sets the three host hooks. `on_paid` runs inside the
492
528
  settlement transaction, only for the first settled attempt for a reference.
493
529
  → [OpenReceive.configure](https://openreceive.org/guides/api-reference.md#openreceiveconfigure)
494
530
 
495
- The engine's controllers inherit from `config.parent_controller` — the
496
- generated initializer sets it to `"ApplicationController"`. That is how the
497
- engine picks up your application's `protect_from_forgery`. Keep
498
- `csrf_meta_tags` in the layout that renders the checkout; the checkout client
499
- sends `X-CSRF-Token` from it automatically.
500
-
501
- The same inheritance brings every global `before_action` your
502
- `ApplicationController` declares. A filter that redirects signed-out users to
503
- a login page will redirect the engine's JSON routes too, and a guest checkout
504
- then never gets an invoice. The engine reads nothing from the parent except
505
- that forgery protection — `config.authorize` receives the request and your
506
- policy reads its own session from it — so if your `ApplicationController`
507
- carries such filters, either point `config.parent_controller` at a slimmer
508
- controller that still calls `protect_from_forgery`, or skip the filter for
509
- the engine only:
531
+ The engine's controllers inherit from `config.parent_controller`. The generated
532
+ initializer sets it to `"ApplicationController"`. That is how the engine picks
533
+ up your application's `protect_from_forgery`. Keep `csrf_meta_tags` in the
534
+ layout that renders the checkout. The checkout client sends `X-CSRF-Token` from
535
+ it automatically.
536
+
537
+ The same inheritance also brings every global `before_action` that your
538
+ `ApplicationController` declares. A filter that redirects signed-out users to a
539
+ login page will redirect the engine's JSON routes too. A guest checkout then
540
+ never gets an invoice. The engine reads nothing from the parent except forgery
541
+ protection. `config.authorize` receives the request, and your policy reads its
542
+ own session from it. So if your `ApplicationController` has such filters, do one
543
+ of these:
544
+
545
+ - Point `config.parent_controller` at a slimmer controller that still calls
546
+ `protect_from_forgery`.
547
+ - Skip the filter for the engine only:
510
548
 
511
549
  ```ruby
512
550
  # config/initializers/openreceive.rb (after OpenReceive.configure)
@@ -515,47 +553,51 @@ Rails.application.config.to_prepare do
515
553
  end
516
554
  ```
517
555
 
518
- Filters your authorize policy depends on (a tenant resolver, `Current`
519
- attributes) should stay: they run before `config.authorize`.
520
-
521
- The generated initializer ships
522
- `config.on_paid = OpenReceive::LOGGING_ON_PAID` — a placeholder that only logs
523
- the settlement and fulfills nothing. Replace it with your real fulfillment (as
524
- above); the engine warns every time your application boots while the
525
- placeholder is still configured, because orders would otherwise be recorded as settled without ever
526
- being fulfilled. The same applies to
527
- `config.authorize = OpenReceive::ALLOW_ALL_AUTHORIZE`, the generated
528
- allow-all placeholder: it treats possession of the reference as
529
- authorization, which is safe only while references are unguessable, and the
530
- engine warns at boot until you replace it with your own ownership check (as
531
- above). Replace both, not just `on_paid`.
532
-
533
- The amount always comes from your own order record; payer-supplied amounts are
534
- rejected. Advanced hooks (`resolve_checkout`, `on_checkout_created`) remain as
535
- overrides for custom-repository applications and are not part of the quickstart.
536
-
537
- For public web shops, opt into the per-IP invoice cap with
538
- `config.rate_limiting = true`; leave it off (the default) when many payers
556
+ Keep the filters your authorize policy depends on, such as a tenant resolver
557
+ or `Current` attributes. They run before `config.authorize`.
558
+
559
+ The generated initializer ships two placeholders. Replace both, not just
560
+ `on_paid`:
561
+
562
+ - `config.on_paid = OpenReceive::LOGGING_ON_PAID` only logs the settlement and
563
+ fulfills nothing. Replace it with your real fulfillment (as above). Until you
564
+ do, orders would be recorded as settled without ever being fulfilled, so the
565
+ engine warns every time your application boots.
566
+ - `config.authorize = OpenReceive::ALLOW_ALL_AUTHORIZE` allows everything. It
567
+ treats possession of the reference as authorization, which is safe only while
568
+ references are unguessable. The engine warns at boot until you replace it
569
+ with your own ownership check (as above).
570
+
571
+ The amount always comes from your own order record. Payer-supplied amounts are
572
+ rejected. The advanced hooks `resolve_checkout` and `on_checkout_created` remain
573
+ as overrides for apps with a custom repository. They are not part of the
574
+ quickstart.
575
+
576
+ For public web shops, turn on the per-IP invoice cap with
577
+ `config.rate_limiting = true`. Leave it off (the default) when many payers
539
578
  share one IP. → [Rate limiting](https://openreceive.org/guides/rate-limiting.md#rails)
540
579
 
541
- In production the engine builds the wallet client — and runs its receive-only
542
- preflight — eagerly when your application boots, so a missing `NWC_URI`, a
543
- dead relay, or a spend-capable wallet stops the deploy instead of surfacing as
544
- customer-facing 500s on the first checkout. Outside production (tests,
545
- consoles) the client is built lazily so no live wallet is needed.
580
+ In production, the engine builds the wallet client when your app boots. It
581
+ also runs the receive-only preflight right away: it reaches the wallet and
582
+ checks that the code cannot spend. A missing `NWC_URI`, a dead relay, or a
583
+ spend-capable wallet then stops the deploy. Otherwise those problems would
584
+ show up as 500 errors for customers on the first checkout. Outside production
585
+ (tests, consoles), the engine builds the client lazily, on first use, so no
586
+ live wallet is needed.
546
587
 
547
588
  ### Render the checkout
548
589
 
549
- Serve the compiled `styles.css` without Tailwind processing: import it from
550
- JavaScript (with a CSS-capable bundler) or use a plain `<link rel="stylesheet">`.
551
- Do not `@import` it into the host Tailwind entry. Its zero-specificity rules
552
- allow host styles to override checkout styles; scoping does not prevent that.
590
+ Serve the compiled `styles.css` without Tailwind processing. Either import it
591
+ from JavaScript (with a CSS-capable bundler) or use a plain
592
+ `<link rel="stylesheet">`. Do not `@import` it into your Tailwind entry. Its
593
+ rules have zero specificity, so your own styles can override checkout styles.
594
+ Scoping does not prevent that.
553
595
 
554
- The engine serves JSON checkout routes only — rendering is your view. Any
555
- OpenReceive frontend package works against the `/openreceive` mount; the
556
- smallest is the custom element (its default `prefix` is already
557
- `/openreceive`, and the package ships a self-contained `styles.css` a plain
558
- stylesheet link can serve; it is scoped to what OpenReceive renders):
596
+ The engine serves JSON checkout routes only. Your view does the rendering. Any
597
+ OpenReceive frontend package works against the `/openreceive` mount. The
598
+ smallest is the custom element. Its default `prefix` is already
599
+ `/openreceive`. The package ships a self-contained `styles.css` that a plain
600
+ stylesheet link can serve, scoped to what OpenReceive renders.
559
601
 
560
602
  ```erb
561
603
  <%# app/views/orders/pay.html.erb %>
@@ -574,9 +616,9 @@ import "@openreceive/elements/styles.css"; // or link the compiled styles.css
574
616
  defineElements();
575
617
  ```
576
618
 
577
- Bundling with esbuild (jsbundling-rails)? Build ESM and load it as a module.
578
- esbuild's default IIFE output evaluates a dependency's Node fallback in the
579
- browser and throws `ReferenceError: __filename is not defined`:
619
+ If you bundle with esbuild (jsbundling-rails), build ESM and load it as a
620
+ module. esbuild's default IIFE output runs a dependency's Node fallback in the
621
+ browser, which throws `ReferenceError: __filename is not defined`:
580
622
 
581
623
  ```sh
582
624
  esbuild app/javascript/application.js --bundle --format=esm --outdir=app/assets/builds
@@ -590,24 +632,24 @@ Everything the checkout draws ships inside the JavaScript: the payment-method
590
632
  icons, the wallet logos and the pay tutorials. There is no image file to copy
591
633
  or serve and no asset option to set. Deploy your normal JavaScript and CSS
592
634
  build output, including any generated JavaScript chunks. Bundlers with code
593
- splitting can defer tutorial screenshots until first open; single-file builds
594
- (including the standalone checkout) include them upfront. If your
595
- Content-Security-Policy has a strict `img-src`, allow `data:`
635
+ splitting can load tutorial screenshots only when a tutorial is first opened.
636
+ Single-file builds, including the standalone checkout, include them upfront. If
637
+ your Content-Security-Policy has a strict `img-src`, allow `data:`
596
638
  ([Provider registry](https://openreceive.org/guides/provider-registry.md#assets)).
597
639
 
598
- Then open the checkout in a browser, confirm the payment-method icons and
640
+ Then open the checkout in a browser. Confirm the payment-method icons and
599
641
  wallet logos render, and open a wallet's pay tutorial to check its screenshots.
600
- If an image is missing, inspect the console for CSP violations and the Network
642
+ If an image is missing, check the console for CSP violations and the Network
601
643
  panel for failed JavaScript chunks. Allow `data:` in `img-src` and deploy the
602
644
  complete build output. Do not add image routes, copy package source images, or
603
645
  use registry `icon_path` / tutorial `path` keys as browser URLs.
604
646
 
605
647
  The element creates the checkout for `reference`, then renders and polls
606
- itself. React/Vue/Svelte/Angular apps use the matching wrapper package
607
- instead — same props and defaults ([Frontend checkout](https://openreceive.org/guides/frontend-checkout.md)).
608
- Build a custom checkout only if this app cannot use a drop-in; then
609
- `@openreceive/browser/headless` is the API
610
- ([Headless checkout](https://openreceive.org/guides/headless-checkout.md)).
648
+ itself. React, Vue, Svelte, and Angular apps use the matching wrapper package
649
+ instead, with the same props and defaults
650
+ ([Frontend checkout](https://openreceive.org/guides/frontend-checkout.md)). Build a custom checkout only if
651
+ this app cannot use a drop-in. In that case `@openreceive/browser/headless` is
652
+ the API ([Headless checkout](https://openreceive.org/guides/headless-checkout.md)).
611
653
 
612
654
  ### Reconciliation
613
655
 
@@ -624,29 +666,33 @@ bin/rails openreceive:notifications
624
666
 
625
667
  → [rake openreceive:notifications](https://openreceive.org/guides/api-reference.md#rake-openreceivenotifications)
626
668
 
627
- `OpenReceive.reconcile!` and `bin/rails openreceive:reconcile` are one-shot
628
- primitives if you want to drive a pass yourself.
669
+ To run a pass yourself, use the one-shot `OpenReceive.reconcile!` or
670
+ `bin/rails openreceive:reconcile`.
629
671
  → [OpenReceive.reconcile!](https://openreceive.org/guides/api-reference.md#openreceivereconcile)
630
672
 
631
673
  ### Swap secrets
632
674
 
633
- The Ruby server recognizes `LSC_URI_PRIMARY` and `LSC_URI_BACKUP` using the
634
- shared [Lightning Swap Connect](https://openreceive.org/guides/lightning-swap-connect.md) vectors: setting either one
635
- auto-builds the matching provider, so an app that wants swaps only supplies the
636
- connection strings ([Environment variables](https://openreceive.org/guides/environment-variables.md)).
637
- `config.swap_providers` is the override knob — pass your own adapters to
638
- replace the auto-built set, or an empty array to disable swaps.
675
+ The Ruby server recognizes `LSC_URI_PRIMARY` and `LSC_URI_BACKUP`, using the
676
+ shared [Lightning Swap Connect](https://openreceive.org/guides/lightning-swap-connect.md) vectors. Setting
677
+ either one auto-builds the matching provider. So an app that wants swaps only
678
+ supplies the connection strings
679
+ ([Environment variables](https://openreceive.org/guides/environment-variables.md)). To override this, use
680
+ `config.swap_providers`. Pass your own adapters to replace the auto-built set,
681
+ or an empty array to disable swaps.
639
682
 
640
- One `openreceive_payments` row holds at most one provider order in its
641
- server-only `swap_data`. The engine filters `swap_data` from Active Record
642
- inspection and ordinary serialization. Do not explicitly serialize it, log it,
643
- or return it from your own API; it may contain a provider credential.
683
+ One `openreceive_payments` row holds at most one provider order, in its
684
+ server-only `swap_data`. The engine hides `swap_data` from Active Record
685
+ inspection and ordinary serialization. Do not serialize it explicitly, log it,
686
+ or return it from your own API. It may contain a provider credential.
644
687
 
645
688
  **Setting either connection string commits you to refunds.** A swap deposit can
646
- arrive short or late, which leaves it `refund_required` at the provider with
647
- only your UI able to claim it — and the payer claims it on a second visit,
648
- after leaving your page for an address in another wallet. That needs a
649
- per-order URL your app serves, a route that restores the order behind it, and
650
- something that restores the ATTEMPT, since `/checkouts/prepare` returns none.
651
- [Swap refunds](https://openreceive.org/guides/swap-refunds.md) is the whole of it; read it before you set
689
+ arrive short or late. The provider then marks it `refund_required`, and only
690
+ your UI can claim it. The payer claims it on a second visit, after leaving your
691
+ page to get an address in another wallet. That needs three things:
692
+
693
+ - a per-order URL your app serves,
694
+ - a route that restores the order behind it,
695
+ - something that restores the ATTEMPT, since `/checkouts/prepare` returns none.
696
+
697
+ [Swap refunds](https://openreceive.org/guides/swap-refunds.md) covers all of it. Read it before you set
652
698
  `LSC_URI_PRIMARY`.