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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +19 -0
- data/lib/openreceive/version.rb +1 -1
- data/skills/debug-openreceive-payment/SKILL.md +1 -1
- data/skills/integrate-openreceive/SKILL.md +4 -3
- data/skills/integrate-openreceive/references/btcpay.md +65 -36
- data/skills/integrate-openreceive/references/django.md +295 -246
- data/skills/integrate-openreceive/references/fastapi.md +210 -157
- data/skills/integrate-openreceive/references/fastify.md +206 -149
- data/skills/integrate-openreceive/references/laravel.md +298 -236
- data/skills/integrate-openreceive/references/next.md +216 -164
- data/skills/integrate-openreceive/references/node.md +194 -140
- data/skills/integrate-openreceive/references/php.md +248 -193
- data/skills/integrate-openreceive/references/rails.md +266 -220
- data/skills/integrate-openreceive/references/woocommerce.md +66 -51
- metadata +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# OpenReceive agent directions (Rails)
|
|
2
2
|
|
|
3
|
-
These directions describe OpenReceive 0.4.
|
|
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.
|
|
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 —
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
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
|
|
134
|
-
|
|
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.
|
|
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
|
|
308
|
-
`openreceive-server` and `nwc-ruby`, so the default wallet client
|
|
309
|
-
|
|
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
|
-
|
|
313
|
-
source
|
|
314
|
-
autotools or `bundle install`
|
|
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
|
-
|
|
331
|
-
|
|
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
|
|
339
|
-
engine tables (`openreceive_payments` and `openreceive_meta`)
|
|
340
|
-
-
|
|
341
|
-
-
|
|
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
|
|
344
|
-
The engine owns the table's commit locking, write-once settlement, and
|
|
345
|
-
reconciliation state machine. `reference` is indexed but not unique
|
|
346
|
-
reference may have many historical attempts
|
|
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
|
|
352
|
-
`status_reason = "duplicate_settlement"` and
|
|
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
|
-
|
|
355
|
-
an order
|
|
356
|
-
those paths race each other
|
|
357
|
-
initializer
|
|
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
|
|
373
|
-
|
|
374
|
-
writes on the order
|
|
375
|
-
rollback and go out again. The `state: "paid"` transition
|
|
376
|
-
|
|
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
|
|
379
|
-
conditional `UPDATE`, so the claim is atomic and
|
|
380
|
-
|
|
381
|
-
post-commit side effect
|
|
382
|
-
|
|
383
|
-
Action Cable, or your model owns the transition through
|
|
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
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
row. Buy a Button's
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
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
|
|
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
|
|
427
|
-
`dotenv-rails`, an exported shell
|
|
428
|
-
|
|
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
|
|
435
|
-
fulfillment identity
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
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
|
|
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
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
The same inheritance brings every global `before_action` your
|
|
502
|
-
`ApplicationController` declares. A filter that redirects signed-out users to
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
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
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
The generated initializer ships
|
|
522
|
-
`
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
being fulfilled
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
authorization, which is safe only while
|
|
530
|
-
engine warns at boot until you replace it
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
The amount always comes from your own order record
|
|
534
|
-
rejected.
|
|
535
|
-
overrides for custom
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
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
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
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
|
|
550
|
-
JavaScript (with a CSS-capable bundler) or use a plain
|
|
551
|
-
Do not `@import` it into
|
|
552
|
-
|
|
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
|
|
555
|
-
OpenReceive frontend package works against the `/openreceive` mount
|
|
556
|
-
smallest is the custom element
|
|
557
|
-
`/openreceive
|
|
558
|
-
stylesheet link can serve
|
|
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
|
-
|
|
578
|
-
esbuild's default IIFE output
|
|
579
|
-
browser
|
|
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
|
|
594
|
-
|
|
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
|
|
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,
|
|
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
|
|
607
|
-
instead
|
|
608
|
-
Build a custom checkout only if
|
|
609
|
-
`@openreceive/browser/headless` is
|
|
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
|
-
|
|
628
|
-
|
|
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
|
|
634
|
-
shared [Lightning Swap Connect](https://openreceive.org/guides/lightning-swap-connect.md) vectors
|
|
635
|
-
auto-builds the matching provider
|
|
636
|
-
connection strings
|
|
637
|
-
|
|
638
|
-
replace the auto-built set,
|
|
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
|
|
642
|
-
inspection and ordinary serialization. Do not
|
|
643
|
-
or return it from your own API
|
|
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
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
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`.
|