@openreceive/node 0.4.10 → 0.4.12

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.10.
3
+ These directions describe OpenReceive 0.4.12.
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
 
@@ -116,7 +139,7 @@ itself, and they hold for every integration.
116
139
  body field. The generator installs `OpenReceive::ALLOW_ALL_AUTHORIZE`, a
117
140
  placeholder that allows everything (the engine warns at boot while it is
118
141
  set) — replace it with this app's real ownership check, same as `on_paid`.
119
- - `config.on_paid` must be idempotent. It runs once per `reference` — your order
142
+ - `config.on_paid` must be idempotent. Its database fulfillment commits once per `reference` — your order
120
143
  id, one per thing you fulfill, created before checkout, kept across retries,
121
144
  never reused. A fresh id per page load lets one order be paid twice.
122
145
  - Receive-only NWC is required; a spend-capable code fails closed at boot unless
@@ -285,6 +308,8 @@ enough; drop the `.md` for the same page a person would read.
285
308
  Questions, or a problem with the library itself:
286
309
  https://openreceive.org/contact
287
310
 
311
+ - https://openreceive.org/guides/payment-safety-upgrade.md — coordinated upgrades and reviewed repair of existing attempts
312
+
288
313
  ---
289
314
 
290
315
  ## The quickstart, in full
@@ -302,15 +327,15 @@ Add the Rails engine gem to your `Gemfile`:
302
327
  gem "openreceive-rails"
303
328
  ```
304
329
 
305
- That is the whole install: `openreceive-rails` depends on `openreceive`,
306
- `openreceive-server` and `nwc-ruby`, so the default wallet client — built from
307
- `NWC_URI` — works with nothing else added. Hosts that bring their own NWC
308
- client set `config.nwc_client` instead.
330
+ That is the whole install. `openreceive-rails` depends on `openreceive`,
331
+ `openreceive-server` and `nwc-ruby`, so the default wallet client works with
332
+ nothing else added. It is built from `NWC_URI`. If your app brings its own NWC
333
+ client, set `config.nwc_client` instead.
309
334
 
310
- One native prerequisite: `nwc-ruby`'s `rbsecp256k1` builds libsecp256k1 from
311
- source, so minimal images (`ruby:3.3-slim`, fresh Docker builds) need the
312
- autotools or `bundle install` dies at `autoreconf: not found`. Before
313
- bundling:
335
+ There is one native prerequisite. `nwc-ruby` uses `rbsecp256k1`, which builds
336
+ libsecp256k1 from source. Minimal images (`ruby:3.3-slim`, fresh Docker builds)
337
+ need the autotools for that, or `bundle install` fails with
338
+ `autoreconf: not found`. Install them before bundling:
314
339
 
315
340
  ```sh
316
341
  apt-get install -y autoconf automake libtool build-essential pkg-config
@@ -325,34 +350,34 @@ bin/rails generate openreceive:install
325
350
  bin/rails db:migrate
326
351
  ```
327
352
 
328
- `openreceive:install` emits one migration for both engine tables, the
329
- initializer, and the engine mount. The migration adapts to the app's configured
330
- database adapter — PostgreSQL, SQLite, and MySQL (`mysql2`/`trilogy`) are
331
- supported.
353
+ The migration adapts to your app's database adapter. PostgreSQL, SQLite, and
354
+ MySQL (`mysql2`/`trilogy`) are supported.
332
355
  → [openreceive:install](https://openreceive.org/guides/api-reference.md#openreceiveinstall)
333
356
 
334
- The generator emits three things:
357
+ The `openreceive:install` generator emits three things:
335
358
 
336
- - `db/migrate/*_create_openreceive_tables.rb` — one migration creating both
337
- engine tables (`openreceive_payments` and `openreceive_meta`);
338
- - a simplified `config/initializers/openreceive.rb`;
339
- - the `OpenReceive::Engine` route mount at `/openreceive`.
359
+ - `db/migrate/*_create_openreceive_tables.rb`: one migration that creates both
360
+ engine tables (`openreceive_payments` and `openreceive_meta`).
361
+ - A simplified `config/initializers/openreceive.rb`.
362
+ - The `OpenReceive::Engine` route mount at `/openreceive`.
340
363
 
341
- The `OpenReceivePayment` model is engine-owned — no model file is generated.
342
- The engine owns the table's commit locking, write-once settlement, and
343
- reconciliation state machine. `reference` is indexed but not unique (a
344
- reference may have many historical attempts); `payment_hash` is globally unique.
364
+ The engine owns the `OpenReceivePayment` model, so no model file is generated.
365
+ The engine also owns the table's commit locking, write-once settlement, and
366
+ reconciliation state machine. `reference` is indexed but not unique, because
367
+ one reference may have many historical attempts. `payment_hash` is globally
368
+ unique.
345
369
 
346
370
  #### Fulfill exactly once
347
371
 
348
372
  Within OpenReceive's own settlement paths, `on_paid` runs at most once per
349
- reference: a second payment to a second invoice is recorded with
350
- `status_reason = "duplicate_settlement"` and never fulfills again.
373
+ reference. If a second invoice for the same reference is paid, OpenReceive
374
+ records that payment with `status_reason = "duplicate_settlement"` and does
375
+ not fulfill again.
351
376
 
352
- The one thing you own: **if anything other than OpenReceive can also fulfill
353
- an order** — an admin action, a second payment processor, a replayed job —
354
- those paths race each other, and `on_paid` must be idempotent. The generated
355
- initializer spells this out and shows the guarded transition:
377
+ One case is yours to handle. **If anything other than OpenReceive can also
378
+ fulfill an order**, such as an admin action, a second payment processor, or a
379
+ replayed job, those paths race each other. Then `on_paid` must be idempotent.
380
+ The generated initializer explains this and shows the guarded transition:
356
381
 
357
382
  ```ruby
358
383
  config.on_paid = lambda do |settlement|
@@ -367,19 +392,19 @@ config.on_paid = lambda do |settlement|
367
392
  end
368
393
  ```
369
394
 
370
- Delivery is at-least-once: `on_paid` runs inside the settlement transaction,
371
- and a raise rolls it back for the next pass to retry. Keep it to database
372
- writes on the order — an email or webhook sent from here would survive the
373
- rollback and go out again. The `state: "paid"` transition above is the flag;
374
- let your own job drain it after commit.
395
+ Delivery is at-least-once. `on_paid` runs inside the settlement transaction. If
396
+ it raises, the transaction rolls back and the next pass retries. So keep
397
+ `on_paid` to database writes on the order. An email or webhook sent from here
398
+ would survive the rollback and go out again. The `state: "paid"` transition
399
+ above is the flag. Let your own job drain it after commit.
375
400
 
376
- **`update_all` fires no Active Record callbacks.** That is the point — it is one
377
- conditional `UPDATE`, so the claim is atomic and there is no model code between
378
- the check and the write. It also means there is no `after_commit` to hang a
379
- post-commit side effect on, which is fine for a background job draining the flag
380
- and useless for a page that wants to know *now*. If you push settlement over
381
- Action Cable, or your model owns the transition through callbacks, take a row
382
- lock for the duration instead:
401
+ **`update_all` fires no Active Record callbacks.** That is intended. It runs one
402
+ conditional `UPDATE`, so the claim is atomic and no model code runs between the
403
+ check and the write. It also means there is no `after_commit` to attach a
404
+ post-commit side effect to. That is fine for a background job that drains the
405
+ flag. It does not help a page that needs to know right away. If you push
406
+ settlement over Action Cable, or your model owns the transition through
407
+ callbacks, take a row lock for the duration instead:
383
408
 
384
409
  ```ruby
385
410
  config.on_paid = lambda do |settlement|
@@ -389,52 +414,61 @@ config.on_paid = lambda do |settlement|
389
414
  end
390
415
  ```
391
416
 
392
- **Unlocking a download works the same way.** If what the payer bought is a
393
- file, do not unlock it in the browser: gate the download route on the paid
394
- order row — `Order.find_by(id: params[:id], user: current_user, state: "paid")`
395
- or a 404 — and serve the file only then. The `state: "paid"` written above is
396
- the unlock; the client never decides an order was fulfilled, it re-reads the
397
- row. Buy a Button's `ShopController#download` is this in twenty lines.
398
-
399
- Both shapes are idempotent, and both are correct. They differ only in whether
400
- your model layer gets to run: `update_all` skips it and is the right default;
401
- the row lock holds the row for the duration of the block and is what you want
402
- when the transition has to go through your model. The generated fulfillment note
403
- says the same thing — if your fulfillment is a read-modify-write that cannot be
404
- expressed as one conditional `UPDATE`, take the lock.
405
-
406
- Either way the rule above still holds: whatever the callback does must be
407
- database writes on the order. `after_commit` on the settlement transaction runs
408
- after OpenReceive's own commit, so an email enqueued there is as safe as one
409
- enqueued from a job draining the flag — and an email sent *inline* from
410
- `on_paid` is not, in either shape.
411
-
412
- A runnable illustration of this boundary — not a template to copy models from —
413
- is Buy a Button
414
- (`examples/buttons/server/rails`).
415
- It has products, visitors, and orders, with the three hooks as the only bridge.
416
- Map that shape onto the models in THIS app.
417
+ **Unlocking a download works the same way.** If the payer bought a file, do not
418
+ unlock it in the browser. Gate the download route on the paid order row, and
419
+ serve the file only if that row exists:
420
+ `Order.find_by(id: params[:id], user: current_user, state: "paid")`, or a 404
421
+ otherwise. The `state: "paid"` written above is the unlock. The client never
422
+ decides that an order was fulfilled. It re-reads the row. Buy a Button's
423
+ `ShopController#download` does this in twenty lines.
424
+
425
+ Both shapes are idempotent and correct. They differ only in whether your model
426
+ layer runs:
427
+
428
+ - `update_all` skips the model layer. It is the right default.
429
+ - The row lock holds the row for the duration of the block. Use it when the
430
+ transition has to go through your model.
431
+
432
+ The generated fulfillment note says the same thing. If your fulfillment is a
433
+ read-modify-write that one conditional `UPDATE` cannot express, take the lock.
434
+
435
+ Either way, the rule above still holds: the callback must only make database
436
+ writes on the order. `after_commit` on the settlement transaction runs after
437
+ OpenReceive's own commit. So an email enqueued there is as safe as one enqueued
438
+ from a job that drains the flag. An email sent *inline* from `on_paid` is not
439
+ safe, in either shape.
440
+
441
+ Buy a Button
442
+ (`examples/buttons/server/rails`)
443
+ is a runnable illustration of this boundary. It is not a template to copy
444
+ models from. It has products, visitors, and orders, and the three hooks are the
445
+ only bridge. Map that shape onto the models in THIS app.
417
446
 
418
447
  Supply the receive-only wallet connection as `ENV["NWC_URI"]`. Never put it in
419
448
  browser code, logs, or assets. Your application refuses to start when the code
420
- advertises spend methods such as `pay_invoice`; the explicit override is
421
- `config.allow_spend_capable_wallet = true` or
449
+ advertises spend methods such as `pay_invoice`. To override that explicitly,
450
+ set `config.allow_spend_capable_wallet = true` or
422
451
  `OPENRECEIVE_ALLOW_SPEND_CAPABLE_NWC=true` ([Security](https://openreceive.org/guides/security.md)).
423
452
 
424
- OpenReceive reads `ENV`; Rails does not load a `.env` file on its own.
425
- `dotenv-rails`, an exported shell environment, or your production secret
426
- manager has to put the values there first.
453
+ OpenReceive reads `ENV`. Rails does not load a `.env` file on its own, so
454
+ something has to put the values there first: `dotenv-rails`, an exported shell
455
+ environment, or your production secret manager.
427
456
  → [Environment variables](https://openreceive.org/guides/environment-variables.md).
428
457
 
429
458
  ### Configure the host hooks
430
459
 
431
460
  The initializer needs three things: authorization, the trusted price, and
432
- fulfillment. All three receive the `reference` — a string you choose, and the
433
- fulfillment identity: your order id, one per thing you fulfill, created before
434
- checkout, kept across retries, never reused. OpenReceive never looks inside
435
- it, but `on_paid` runs once per reference, a new checkout under a reference
436
- that already settled is refused with 409, and a fresh id per page load lets
437
- one order be paid twice.
461
+ fulfillment. All three receive the `reference`. This is a string you choose,
462
+ and it is the fulfillment identity. Use your order id:
463
+
464
+ - one per thing you fulfill,
465
+ - created before checkout,
466
+ - kept across retries,
467
+ - never reused.
468
+
469
+ OpenReceive never looks inside it. But `on_paid` commits fulfillment once per
470
+ reference, and a new checkout under a reference that already settled is
471
+ refused with 409. A fresh id per page load would let one order be paid twice.
438
472
 
439
473
  ```ruby
440
474
  OpenReceive.configure do |config|
@@ -486,25 +520,27 @@ OpenReceive.configure do |config|
486
520
  end
487
521
  ```
488
522
 
489
- `OpenReceive.configure` sets the three host hooks; `on_paid` runs inside the
523
+ `OpenReceive.configure` sets the three host hooks. `on_paid` runs inside the
490
524
  settlement transaction, only for the first settled attempt for a reference.
491
525
  → [OpenReceive.configure](https://openreceive.org/guides/api-reference.md#openreceiveconfigure)
492
526
 
493
- The engine's controllers inherit from `config.parent_controller` — the
494
- generated initializer sets it to `"ApplicationController"`. That is how the
495
- engine picks up your application's `protect_from_forgery`. Keep
496
- `csrf_meta_tags` in the layout that renders the checkout; the checkout client
497
- sends `X-CSRF-Token` from it automatically.
498
-
499
- The same inheritance brings every global `before_action` your
500
- `ApplicationController` declares. A filter that redirects signed-out users to
501
- a login page will redirect the engine's JSON routes too, and a guest checkout
502
- then never gets an invoice. The engine reads nothing from the parent except
503
- that forgery protection — `config.authorize` receives the request and your
504
- policy reads its own session from it — so if your `ApplicationController`
505
- carries such filters, either point `config.parent_controller` at a slimmer
506
- controller that still calls `protect_from_forgery`, or skip the filter for
507
- the engine only:
527
+ The engine's controllers inherit from `config.parent_controller`. The generated
528
+ initializer sets it to `"ApplicationController"`. That is how the engine picks
529
+ up your application's `protect_from_forgery`. Keep `csrf_meta_tags` in the
530
+ layout that renders the checkout. The checkout client sends `X-CSRF-Token` from
531
+ it automatically.
532
+
533
+ The same inheritance also brings every global `before_action` that your
534
+ `ApplicationController` declares. A filter that redirects signed-out users to a
535
+ login page will redirect the engine's JSON routes too. A guest checkout then
536
+ never gets an invoice. The engine reads nothing from the parent except forgery
537
+ protection. `config.authorize` receives the request, and your policy reads its
538
+ own session from it. So if your `ApplicationController` has such filters, do one
539
+ of these:
540
+
541
+ - Point `config.parent_controller` at a slimmer controller that still calls
542
+ `protect_from_forgery`.
543
+ - Skip the filter for the engine only:
508
544
 
509
545
  ```ruby
510
546
  # config/initializers/openreceive.rb (after OpenReceive.configure)
@@ -513,47 +549,51 @@ Rails.application.config.to_prepare do
513
549
  end
514
550
  ```
515
551
 
516
- Filters your authorize policy depends on (a tenant resolver, `Current`
517
- attributes) should stay: they run before `config.authorize`.
518
-
519
- The generated initializer ships
520
- `config.on_paid = OpenReceive::LOGGING_ON_PAID` — a placeholder that only logs
521
- the settlement and fulfills nothing. Replace it with your real fulfillment (as
522
- above); the engine warns every time your application boots while the
523
- placeholder is still configured, because orders would otherwise be recorded as settled without ever
524
- being fulfilled. The same applies to
525
- `config.authorize = OpenReceive::ALLOW_ALL_AUTHORIZE`, the generated
526
- allow-all placeholder: it treats possession of the reference as
527
- authorization, which is safe only while references are unguessable, and the
528
- engine warns at boot until you replace it with your own ownership check (as
529
- above). Replace both, not just `on_paid`.
530
-
531
- The amount always comes from your own order record; payer-supplied amounts are
532
- rejected. Advanced hooks (`resolve_checkout`, `on_checkout_created`) remain as
533
- overrides for custom-repository applications and are not part of the quickstart.
534
-
535
- For public web shops, opt into the per-IP invoice cap with
536
- `config.rate_limiting = true`; leave it off (the default) when many payers
552
+ Keep the filters your authorize policy depends on, such as a tenant resolver
553
+ or `Current` attributes. They run before `config.authorize`.
554
+
555
+ The generated initializer ships two placeholders. Replace both, not just
556
+ `on_paid`:
557
+
558
+ - `config.on_paid = OpenReceive::LOGGING_ON_PAID` only logs the settlement and
559
+ fulfills nothing. Replace it with your real fulfillment (as above). Until you
560
+ do, orders would be recorded as settled without ever being fulfilled, so the
561
+ engine warns every time your application boots.
562
+ - `config.authorize = OpenReceive::ALLOW_ALL_AUTHORIZE` allows everything. It
563
+ treats possession of the reference as authorization, which is safe only while
564
+ references are unguessable. The engine warns at boot until you replace it
565
+ with your own ownership check (as above).
566
+
567
+ The amount always comes from your own order record. Payer-supplied amounts are
568
+ rejected. The advanced hooks `resolve_checkout` and `on_checkout_created` remain
569
+ as overrides for apps with a custom repository. They are not part of the
570
+ quickstart.
571
+
572
+ For public web shops, turn on the per-IP invoice cap with
573
+ `config.rate_limiting = true`. Leave it off (the default) when many payers
537
574
  share one IP. → [Rate limiting](https://openreceive.org/guides/rate-limiting.md#rails)
538
575
 
539
- In production the engine builds the wallet client — and runs its receive-only
540
- preflight — eagerly when your application boots, so a missing `NWC_URI`, a
541
- dead relay, or a spend-capable wallet stops the deploy instead of surfacing as
542
- customer-facing 500s on the first checkout. Outside production (tests,
543
- consoles) the client is built lazily so no live wallet is needed.
576
+ In production, the engine builds the wallet client when your app boots. It
577
+ also runs the receive-only preflight right away: it reaches the wallet and
578
+ checks that the code cannot spend. A missing `NWC_URI`, a dead relay, or a
579
+ spend-capable wallet then stops the deploy. Otherwise those problems would
580
+ show up as 500 errors for customers on the first checkout. Outside production
581
+ (tests, consoles), the engine builds the client lazily, on first use, so no
582
+ live wallet is needed.
544
583
 
545
584
  ### Render the checkout
546
585
 
547
- Serve the compiled `styles.css` without Tailwind processing: import it from
548
- JavaScript (with a CSS-capable bundler) or use a plain `<link rel="stylesheet">`.
549
- Do not `@import` it into the host Tailwind entry. Its zero-specificity rules
550
- allow host styles to override checkout styles; scoping does not prevent that.
586
+ Serve the compiled `styles.css` without Tailwind processing. Either import it
587
+ from JavaScript (with a CSS-capable bundler) or use a plain
588
+ `<link rel="stylesheet">`. Do not `@import` it into your Tailwind entry. Its
589
+ rules have zero specificity, so your own styles can override checkout styles.
590
+ Scoping does not prevent that.
551
591
 
552
- The engine serves JSON checkout routes only — rendering is your view. Any
553
- OpenReceive frontend package works against the `/openreceive` mount; the
554
- smallest is the custom element (its default `prefix` is already
555
- `/openreceive`, and the package ships a self-contained `styles.css` a plain
556
- stylesheet link can serve; it is scoped to what OpenReceive renders):
592
+ The engine serves JSON checkout routes only. Your view does the rendering. Any
593
+ OpenReceive frontend package works against the `/openreceive` mount. The
594
+ smallest is the custom element. Its default `prefix` is already
595
+ `/openreceive`. The package ships a self-contained `styles.css` that a plain
596
+ stylesheet link can serve, scoped to what OpenReceive renders.
557
597
 
558
598
  ```erb
559
599
  <%# app/views/orders/pay.html.erb %>
@@ -572,9 +612,9 @@ import "@openreceive/elements/styles.css"; // or link the compiled styles.css
572
612
  defineElements();
573
613
  ```
574
614
 
575
- Bundling with esbuild (jsbundling-rails)? Build ESM and load it as a module.
576
- esbuild's default IIFE output evaluates a dependency's Node fallback in the
577
- browser and throws `ReferenceError: __filename is not defined`:
615
+ If you bundle with esbuild (jsbundling-rails), build ESM and load it as a
616
+ module. esbuild's default IIFE output runs a dependency's Node fallback in the
617
+ browser, which throws `ReferenceError: __filename is not defined`:
578
618
 
579
619
  ```sh
580
620
  esbuild app/javascript/application.js --bundle --format=esm --outdir=app/assets/builds
@@ -588,24 +628,24 @@ Everything the checkout draws ships inside the JavaScript: the payment-method
588
628
  icons, the wallet logos and the pay tutorials. There is no image file to copy
589
629
  or serve and no asset option to set. Deploy your normal JavaScript and CSS
590
630
  build output, including any generated JavaScript chunks. Bundlers with code
591
- splitting can defer tutorial screenshots until first open; single-file builds
592
- (including the standalone checkout) include them upfront. If your
593
- Content-Security-Policy has a strict `img-src`, allow `data:`
631
+ splitting can load tutorial screenshots only when a tutorial is first opened.
632
+ Single-file builds, including the standalone checkout, include them upfront. If
633
+ your Content-Security-Policy has a strict `img-src`, allow `data:`
594
634
  ([Provider registry](https://openreceive.org/guides/provider-registry.md#assets)).
595
635
 
596
- Then open the checkout in a browser, confirm the payment-method icons and
636
+ Then open the checkout in a browser. Confirm the payment-method icons and
597
637
  wallet logos render, and open a wallet's pay tutorial to check its screenshots.
598
- If an image is missing, inspect the console for CSP violations and the Network
638
+ If an image is missing, check the console for CSP violations and the Network
599
639
  panel for failed JavaScript chunks. Allow `data:` in `img-src` and deploy the
600
640
  complete build output. Do not add image routes, copy package source images, or
601
641
  use registry `icon_path` / tutorial `path` keys as browser URLs.
602
642
 
603
643
  The element creates the checkout for `reference`, then renders and polls
604
- itself. React/Vue/Svelte/Angular apps use the matching wrapper package
605
- instead — same props and defaults ([Frontend checkout](https://openreceive.org/guides/frontend-checkout.md)).
606
- Build a custom checkout only if this app cannot use a drop-in; then
607
- `@openreceive/browser/headless` is the API
608
- ([Headless checkout](https://openreceive.org/guides/headless-checkout.md)).
644
+ itself. React, Vue, Svelte, and Angular apps use the matching wrapper package
645
+ instead, with the same props and defaults
646
+ ([Frontend checkout](https://openreceive.org/guides/frontend-checkout.md)). Build a custom checkout only if
647
+ this app cannot use a drop-in. In that case `@openreceive/browser/headless` is
648
+ the API ([Headless checkout](https://openreceive.org/guides/headless-checkout.md)).
609
649
 
610
650
  ### Reconciliation
611
651
 
@@ -622,29 +662,33 @@ bin/rails openreceive:notifications
622
662
 
623
663
  → [rake openreceive:notifications](https://openreceive.org/guides/api-reference.md#rake-openreceivenotifications)
624
664
 
625
- `OpenReceive.reconcile!` and `bin/rails openreceive:reconcile` are one-shot
626
- primitives if you want to drive a pass yourself.
665
+ To run a pass yourself, use the one-shot `OpenReceive.reconcile!` or
666
+ `bin/rails openreceive:reconcile`.
627
667
  → [OpenReceive.reconcile!](https://openreceive.org/guides/api-reference.md#openreceivereconcile)
628
668
 
629
669
  ### Swap secrets
630
670
 
631
- The Ruby server recognizes `LSC_URI_PRIMARY` and `LSC_URI_BACKUP` using the
632
- shared [Lightning Swap Connect](https://openreceive.org/guides/lightning-swap-connect.md) vectors: setting either one
633
- auto-builds the matching provider, so an app that wants swaps only supplies the
634
- connection strings ([Environment variables](https://openreceive.org/guides/environment-variables.md)).
635
- `config.swap_providers` is the override knob — pass your own adapters to
636
- replace the auto-built set, or an empty array to disable swaps.
671
+ The Ruby server recognizes `LSC_URI_PRIMARY` and `LSC_URI_BACKUP`, using the
672
+ shared [Lightning Swap Connect](https://openreceive.org/guides/lightning-swap-connect.md) vectors. Setting
673
+ either one auto-builds the matching provider. So an app that wants swaps only
674
+ supplies the connection strings
675
+ ([Environment variables](https://openreceive.org/guides/environment-variables.md)). To override this, use
676
+ `config.swap_providers`. Pass your own adapters to replace the auto-built set,
677
+ or an empty array to disable swaps.
637
678
 
638
- One `openreceive_payments` row holds at most one provider order in its
639
- server-only `swap_data`. The engine filters `swap_data` from Active Record
640
- inspection and ordinary serialization. Do not explicitly serialize it, log it,
641
- or return it from your own API; it may contain a provider credential.
679
+ One `openreceive_payments` row holds at most one provider order, in its
680
+ server-only `swap_data`. The engine hides `swap_data` from Active Record
681
+ inspection and ordinary serialization. Do not serialize it explicitly, log it,
682
+ or return it from your own API. It may contain a provider credential.
642
683
 
643
684
  **Setting either connection string commits you to refunds.** A swap deposit can
644
- arrive short or late, which leaves it `refund_required` at the provider with
645
- only your UI able to claim it — and the payer claims it on a second visit,
646
- after leaving your page for an address in another wallet. That needs a
647
- per-order URL your app serves, a route that restores the order behind it, and
648
- something that restores the ATTEMPT, since `/checkouts/prepare` returns none.
649
- [Swap refunds](https://openreceive.org/guides/swap-refunds.md) is the whole of it; read it before you set
685
+ arrive short or late. The provider then marks it `refund_required`, and only
686
+ your UI can claim it. The payer claims it on a second visit, after leaving your
687
+ page to get an address in another wallet. That needs three things:
688
+
689
+ - a per-order URL your app serves,
690
+ - a route that restores the order behind it,
691
+ - something that restores the ATTEMPT, since `/checkouts/prepare` returns none.
692
+
693
+ [Swap refunds](https://openreceive.org/guides/swap-refunds.md) covers all of it. Read it before you set
650
694
  `LSC_URI_PRIMARY`.