@openreceive/svelte 0.4.11 → 0.4.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -3
- package/skills/debug-openreceive-payment/SKILL.md +1 -1
- package/skills/integrate-openreceive/SKILL.md +4 -3
- package/skills/integrate-openreceive/references/btcpay.md +65 -36
- package/skills/integrate-openreceive/references/django.md +288 -243
- package/skills/integrate-openreceive/references/fastapi.md +203 -154
- package/skills/integrate-openreceive/references/fastify.md +197 -146
- package/skills/integrate-openreceive/references/laravel.md +291 -233
- package/skills/integrate-openreceive/references/next.md +207 -161
- package/skills/integrate-openreceive/references/node.md +185 -137
- package/skills/integrate-openreceive/references/php.md +245 -192
- package/skills/integrate-openreceive/references/rails.md +259 -217
- package/skills/integrate-openreceive/references/woocommerce.md +66 -51
|
@@ -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.13.
|
|
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
|
|
|
@@ -304,15 +327,15 @@ Add the Rails engine gem to your `Gemfile`:
|
|
|
304
327
|
gem "openreceive-rails"
|
|
305
328
|
```
|
|
306
329
|
|
|
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.
|
|
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.
|
|
311
334
|
|
|
312
|
-
|
|
313
|
-
source
|
|
314
|
-
autotools or `bundle install`
|
|
315
|
-
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:
|
|
316
339
|
|
|
317
340
|
```sh
|
|
318
341
|
apt-get install -y autoconf automake libtool build-essential pkg-config
|
|
@@ -327,34 +350,34 @@ bin/rails generate openreceive:install
|
|
|
327
350
|
bin/rails db:migrate
|
|
328
351
|
```
|
|
329
352
|
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
database adapter — PostgreSQL, SQLite, and MySQL (`mysql2`/`trilogy`) are
|
|
333
|
-
supported.
|
|
353
|
+
The migration adapts to your app's database adapter. PostgreSQL, SQLite, and
|
|
354
|
+
MySQL (`mysql2`/`trilogy`) are supported.
|
|
334
355
|
→ [openreceive:install](https://openreceive.org/guides/api-reference.md#openreceiveinstall)
|
|
335
356
|
|
|
336
|
-
The generator emits three things:
|
|
357
|
+
The `openreceive:install` generator emits three things:
|
|
337
358
|
|
|
338
|
-
- `db/migrate/*_create_openreceive_tables.rb
|
|
339
|
-
engine tables (`openreceive_payments` and `openreceive_meta`)
|
|
340
|
-
-
|
|
341
|
-
-
|
|
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`.
|
|
342
363
|
|
|
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
|
|
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.
|
|
347
369
|
|
|
348
370
|
#### Fulfill exactly once
|
|
349
371
|
|
|
350
372
|
Within OpenReceive's own settlement paths, `on_paid` runs at most once per
|
|
351
|
-
reference
|
|
352
|
-
`status_reason = "duplicate_settlement"` and
|
|
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.
|
|
353
376
|
|
|
354
|
-
|
|
355
|
-
an order
|
|
356
|
-
those paths race each other
|
|
357
|
-
initializer
|
|
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:
|
|
358
381
|
|
|
359
382
|
```ruby
|
|
360
383
|
config.on_paid = lambda do |settlement|
|
|
@@ -369,19 +392,19 @@ config.on_paid = lambda do |settlement|
|
|
|
369
392
|
end
|
|
370
393
|
```
|
|
371
394
|
|
|
372
|
-
Delivery is at-least-once
|
|
373
|
-
|
|
374
|
-
writes on the order
|
|
375
|
-
rollback and go out again. The `state: "paid"` transition
|
|
376
|
-
|
|
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.
|
|
377
400
|
|
|
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:
|
|
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:
|
|
385
408
|
|
|
386
409
|
```ruby
|
|
387
410
|
config.on_paid = lambda do |settlement|
|
|
@@ -391,52 +414,61 @@ config.on_paid = lambda do |settlement|
|
|
|
391
414
|
end
|
|
392
415
|
```
|
|
393
416
|
|
|
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
|
-
|
|
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.
|
|
419
446
|
|
|
420
447
|
Supply the receive-only wallet connection as `ENV["NWC_URI"]`. Never put it in
|
|
421
448
|
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
|
|
449
|
+
advertises spend methods such as `pay_invoice`. To override that explicitly,
|
|
450
|
+
set `config.allow_spend_capable_wallet = true` or
|
|
424
451
|
`OPENRECEIVE_ALLOW_SPEND_CAPABLE_NWC=true` ([Security](https://openreceive.org/guides/security.md)).
|
|
425
452
|
|
|
426
|
-
OpenReceive reads `ENV
|
|
427
|
-
`dotenv-rails`, an exported shell
|
|
428
|
-
|
|
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.
|
|
429
456
|
→ [Environment variables](https://openreceive.org/guides/environment-variables.md).
|
|
430
457
|
|
|
431
458
|
### Configure the host hooks
|
|
432
459
|
|
|
433
460
|
The initializer needs three things: authorization, the trusted price, and
|
|
434
|
-
fulfillment. All three receive the `reference
|
|
435
|
-
fulfillment identity
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
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.
|
|
440
472
|
|
|
441
473
|
```ruby
|
|
442
474
|
OpenReceive.configure do |config|
|
|
@@ -488,25 +520,27 @@ OpenReceive.configure do |config|
|
|
|
488
520
|
end
|
|
489
521
|
```
|
|
490
522
|
|
|
491
|
-
`OpenReceive.configure` sets the three host hooks
|
|
523
|
+
`OpenReceive.configure` sets the three host hooks. `on_paid` runs inside the
|
|
492
524
|
settlement transaction, only for the first settled attempt for a reference.
|
|
493
525
|
→ [OpenReceive.configure](https://openreceive.org/guides/api-reference.md#openreceiveconfigure)
|
|
494
526
|
|
|
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
|
-
|
|
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:
|
|
510
544
|
|
|
511
545
|
```ruby
|
|
512
546
|
# config/initializers/openreceive.rb (after OpenReceive.configure)
|
|
@@ -515,47 +549,51 @@ Rails.application.config.to_prepare do
|
|
|
515
549
|
end
|
|
516
550
|
```
|
|
517
551
|
|
|
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
|
-
|
|
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
|
|
539
574
|
share one IP. → [Rate limiting](https://openreceive.org/guides/rate-limiting.md#rails)
|
|
540
575
|
|
|
541
|
-
In production the engine builds the wallet client
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
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.
|
|
546
583
|
|
|
547
584
|
### Render the checkout
|
|
548
585
|
|
|
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
|
-
|
|
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.
|
|
553
591
|
|
|
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
|
|
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.
|
|
559
597
|
|
|
560
598
|
```erb
|
|
561
599
|
<%# app/views/orders/pay.html.erb %>
|
|
@@ -574,9 +612,9 @@ import "@openreceive/elements/styles.css"; // or link the compiled styles.css
|
|
|
574
612
|
defineElements();
|
|
575
613
|
```
|
|
576
614
|
|
|
577
|
-
|
|
578
|
-
esbuild's default IIFE output
|
|
579
|
-
browser
|
|
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`:
|
|
580
618
|
|
|
581
619
|
```sh
|
|
582
620
|
esbuild app/javascript/application.js --bundle --format=esm --outdir=app/assets/builds
|
|
@@ -590,24 +628,24 @@ Everything the checkout draws ships inside the JavaScript: the payment-method
|
|
|
590
628
|
icons, the wallet logos and the pay tutorials. There is no image file to copy
|
|
591
629
|
or serve and no asset option to set. Deploy your normal JavaScript and CSS
|
|
592
630
|
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:`
|
|
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:`
|
|
596
634
|
([Provider registry](https://openreceive.org/guides/provider-registry.md#assets)).
|
|
597
635
|
|
|
598
|
-
Then open the checkout in a browser
|
|
636
|
+
Then open the checkout in a browser. Confirm the payment-method icons and
|
|
599
637
|
wallet logos render, and open a wallet's pay tutorial to check its screenshots.
|
|
600
|
-
If an image is missing,
|
|
638
|
+
If an image is missing, check the console for CSP violations and the Network
|
|
601
639
|
panel for failed JavaScript chunks. Allow `data:` in `img-src` and deploy the
|
|
602
640
|
complete build output. Do not add image routes, copy package source images, or
|
|
603
641
|
use registry `icon_path` / tutorial `path` keys as browser URLs.
|
|
604
642
|
|
|
605
643
|
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)).
|
|
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)).
|
|
611
649
|
|
|
612
650
|
### Reconciliation
|
|
613
651
|
|
|
@@ -624,29 +662,33 @@ bin/rails openreceive:notifications
|
|
|
624
662
|
|
|
625
663
|
→ [rake openreceive:notifications](https://openreceive.org/guides/api-reference.md#rake-openreceivenotifications)
|
|
626
664
|
|
|
627
|
-
|
|
628
|
-
|
|
665
|
+
To run a pass yourself, use the one-shot `OpenReceive.reconcile!` or
|
|
666
|
+
`bin/rails openreceive:reconcile`.
|
|
629
667
|
→ [OpenReceive.reconcile!](https://openreceive.org/guides/api-reference.md#openreceivereconcile)
|
|
630
668
|
|
|
631
669
|
### Swap secrets
|
|
632
670
|
|
|
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,
|
|
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.
|
|
639
678
|
|
|
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
|
|
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.
|
|
644
683
|
|
|
645
684
|
**Setting either connection string commits you to refunds.** A swap deposit can
|
|
646
|
-
arrive short or late
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
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
|
|
652
694
|
`LSC_URI_PRIMARY`.
|