openreceive 0.4.2 → 0.4.4
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 +24 -0
- data/lib/openreceive/core.rb +14 -14
- data/lib/openreceive/generated/tables.rb +290 -0
- data/lib/openreceive/version.rb +1 -1
- data/lib/openreceive.rb +3 -0
- data/skills/integrate-openreceive/SKILL.md +15 -5
- data/skills/integrate-openreceive/references/btcpay.md +193 -0
- data/skills/integrate-openreceive/references/django.md +667 -0
- data/skills/integrate-openreceive/references/fastapi.md +537 -0
- data/skills/integrate-openreceive/references/fastify.md +529 -0
- data/skills/integrate-openreceive/references/laravel.md +658 -0
- data/skills/integrate-openreceive/references/next.md +580 -0
- data/skills/integrate-openreceive/references/node.md +33 -14
- data/skills/integrate-openreceive/references/php.md +598 -0
- data/skills/integrate-openreceive/references/rails.md +72 -27
- metadata +9 -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.4.
|
|
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
|
|
@@ -14,6 +14,13 @@ models (`ShopOrder`, `ShopUser`, a signed-cookie visitor) over tables that
|
|
|
14
14
|
already exist. Find this application's order, product, and user models — whatever
|
|
15
15
|
they are actually named — and map the three hooks onto those.
|
|
16
16
|
|
|
17
|
+
Keep this application's view layer, its Devise/session authentication and its
|
|
18
|
+
database. Pick the frontend package that matches what already renders here
|
|
19
|
+
(`@openreceive/elements` for ERB/Hotwire; `/react`, `/vue`, `/svelte` or
|
|
20
|
+
`/angular` for an existing SPA) — do not add React to a Hotwire app. Reuse the
|
|
21
|
+
app's existing session or `current_user` in `config.authorize`; the engine's
|
|
22
|
+
migration adds only its own two tables to the app's database.
|
|
23
|
+
|
|
17
24
|
## What OpenReceive is
|
|
18
25
|
|
|
19
26
|
A payment library that runs inside YOUR server. It mounts HTTP routes in the
|
|
@@ -217,8 +224,12 @@ built on `@openreceive/browser/headless`. Read that before writing components.
|
|
|
217
224
|
"switch payment method".
|
|
218
225
|
- No "Open wallet" button on desktop.
|
|
219
226
|
- Wallet suggestions: `getPaymentWizardRoutes()` +
|
|
220
|
-
`createWizardRouteDisplays`. Lightning only.
|
|
221
|
-
|
|
227
|
+
`createWizardRouteDisplays`. Lightning only. Every image ships inside
|
|
228
|
+
the JavaScript — logos as data URIs, tutorials once `loadPayTutorialImages()`
|
|
229
|
+
resolves (`image` is `undefined` until then) — so serve nothing and set no
|
|
230
|
+
asset option. When it works, the logos and payment icons render; a missing
|
|
231
|
+
image means a CSP `img-src` that blocks `data:`, and the console names it.
|
|
232
|
+
The registry answers ~37 wallets: pass
|
|
222
233
|
`providerPreviewLimit` and build "show all" from `display.providerCount`,
|
|
223
234
|
or they push the QR off the screen.
|
|
224
235
|
|
|
@@ -233,10 +244,9 @@ enough; drop the `.md` for the same page a person would read.
|
|
|
233
244
|
- https://openreceive.org/guides/frontend-checkout.md — the drop-in's props, attributes and slots
|
|
234
245
|
- https://openreceive.org/guides/checkout-ux.md — read before building any custom UI
|
|
235
246
|
- https://openreceive.org/guides/headless-checkout.md — the controller, the display models, refunds
|
|
236
|
-
- https://openreceive.org/guides/provider-registry.md — where the
|
|
237
|
-
tutorials come from,
|
|
238
|
-
|
|
239
|
-
in checkout-ux.md
|
|
247
|
+
- https://openreceive.org/guides/provider-registry.md — where the wallet logos and pay
|
|
248
|
+
tutorials come from: inside the JavaScript, nothing to serve. This is the page
|
|
249
|
+
that owns the image rule, not the summary in checkout-ux.md
|
|
240
250
|
- https://openreceive.org/guides/automated-swaps.md — only if `LSC_URI_PRIMARY` is set
|
|
241
251
|
- https://openreceive.org/guides/swap-refunds.md — the refund flow, and the route back to it. Read it before you turn swaps on
|
|
242
252
|
- https://openreceive.org/guides/lightning-swap-connect.md — what an `LSC_URI_*` code actually is
|
|
@@ -261,7 +271,7 @@ passes. The page it comes from is https://openreceive.org/guides/quickstart-rail
|
|
|
261
271
|
|
|
262
272
|
## Rails quickstart
|
|
263
273
|
|
|
264
|
-
Requires Ruby ≥ 3.2.
|
|
274
|
+
Requires Ruby ≥ 3.2 and Rails ≥ 8.0.
|
|
265
275
|
|
|
266
276
|
Add the Rails engine gem to your `Gemfile`:
|
|
267
277
|
|
|
@@ -356,6 +366,13 @@ config.on_paid = lambda do |settlement|
|
|
|
356
366
|
end
|
|
357
367
|
```
|
|
358
368
|
|
|
369
|
+
**Unlocking a download works the same way.** If what the payer bought is a
|
|
370
|
+
file, do not unlock it in the browser: gate the download route on the paid
|
|
371
|
+
order row — `Order.find_by(id: params[:id], user: current_user, state: "paid")`
|
|
372
|
+
or a 404 — and serve the file only then. The `state: "paid"` written above is
|
|
373
|
+
the unlock; the client never decides an order was fulfilled, it re-reads the
|
|
374
|
+
row. Buy a Button's `ShopController#download` is this in twenty lines.
|
|
375
|
+
|
|
359
376
|
Both shapes are idempotent, and both are correct. They differ only in whether
|
|
360
377
|
your model layer gets to run: `update_all` skips it and is the right default;
|
|
361
378
|
the row lock holds the row for the duration of the block and is what you want
|
|
@@ -450,10 +467,32 @@ end
|
|
|
450
467
|
settlement transaction, only for the first settled attempt for a reference.
|
|
451
468
|
→ [OpenReceive.configure](https://openreceive.org/guides/api-reference.md#openreceiveconfigure)
|
|
452
469
|
|
|
453
|
-
The engine
|
|
470
|
+
The engine's controllers inherit from `config.parent_controller` — the
|
|
471
|
+
generated initializer sets it to `"ApplicationController"`. That is how the
|
|
472
|
+
engine picks up your application's `protect_from_forgery`. Keep
|
|
454
473
|
`csrf_meta_tags` in the layout that renders the checkout; the checkout client
|
|
455
474
|
sends `X-CSRF-Token` from it automatically.
|
|
456
475
|
|
|
476
|
+
The same inheritance brings every global `before_action` your
|
|
477
|
+
`ApplicationController` declares. A filter that redirects signed-out users to
|
|
478
|
+
a login page will redirect the engine's JSON routes too, and a guest checkout
|
|
479
|
+
then never gets an invoice. The engine reads nothing from the parent except
|
|
480
|
+
that forgery protection — `config.authorize` receives the request and your
|
|
481
|
+
policy reads its own session from it — so if your `ApplicationController`
|
|
482
|
+
carries such filters, either point `config.parent_controller` at a slimmer
|
|
483
|
+
controller that still calls `protect_from_forgery`, or skip the filter for
|
|
484
|
+
the engine only:
|
|
485
|
+
|
|
486
|
+
```ruby
|
|
487
|
+
# config/initializers/openreceive.rb (after OpenReceive.configure)
|
|
488
|
+
Rails.application.config.to_prepare do
|
|
489
|
+
OpenReceive::ApplicationController.skip_before_action :require_login
|
|
490
|
+
end
|
|
491
|
+
```
|
|
492
|
+
|
|
493
|
+
Filters your authorize policy depends on (a tenant resolver, `Current`
|
|
494
|
+
attributes) should stay: they run before `config.authorize`.
|
|
495
|
+
|
|
457
496
|
The generated initializer ships
|
|
458
497
|
`config.on_paid = OpenReceive::LOGGING_ON_PAID` — a placeholder that only logs
|
|
459
498
|
the settlement and fulfills nothing. Replace it with your real fulfillment (as
|
|
@@ -506,27 +545,33 @@ import "@openreceive/elements/styles.css"; // or link the compiled styles.css
|
|
|
506
545
|
defineElements();
|
|
507
546
|
```
|
|
508
547
|
|
|
509
|
-
Bundling with esbuild (jsbundling-rails)?
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
a dependency's Node fallback in the browser and throws
|
|
513
|
-
`ReferenceError: __filename is not defined`:
|
|
548
|
+
Bundling with esbuild (jsbundling-rails)? Build ESM and load it as a module.
|
|
549
|
+
esbuild's default IIFE output evaluates a dependency's Node fallback in the
|
|
550
|
+
browser and throws `ReferenceError: __filename is not defined`:
|
|
514
551
|
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
552
|
+
```sh
|
|
553
|
+
esbuild app/javascript/application.js --bundle --format=esm --outdir=app/assets/builds
|
|
554
|
+
```
|
|
518
555
|
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
556
|
+
```erb
|
|
557
|
+
<%= javascript_include_tag "application", type: "module" %>
|
|
558
|
+
```
|
|
522
559
|
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
560
|
+
Everything the checkout draws ships inside the JavaScript: the payment-method
|
|
561
|
+
icons, the wallet logos and the pay tutorials. There is no image file to copy
|
|
562
|
+
or serve and no asset option to set. Deploy your normal JavaScript and CSS
|
|
563
|
+
build output, including any generated JavaScript chunks. Bundlers with code
|
|
564
|
+
splitting can defer tutorial screenshots until first open; single-file builds
|
|
565
|
+
(including the standalone checkout) include them upfront. If your
|
|
566
|
+
Content-Security-Policy has a strict `img-src`, allow `data:`
|
|
567
|
+
([Provider registry](https://openreceive.org/guides/provider-registry.md#assets)).
|
|
568
|
+
|
|
569
|
+
Then open the checkout in a browser, confirm the payment-method icons and
|
|
570
|
+
wallet logos render, and open a wallet's pay tutorial to check its screenshots.
|
|
571
|
+
If an image is missing, inspect the console for CSP violations and the Network
|
|
572
|
+
panel for failed JavaScript chunks. Allow `data:` in `img-src` and deploy the
|
|
573
|
+
complete build output. Do not add image routes, copy package source images, or
|
|
574
|
+
use registry `icon_path` / tutorial `path` keys as browser URLs.
|
|
530
575
|
|
|
531
576
|
The element creates the checkout for `reference`, then renders and polls
|
|
532
577
|
itself. React/Vue/Svelte/Angular apps use the matching wrapper package
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: openreceive
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.4.
|
|
4
|
+
version: 0.4.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- OpenReceive
|
|
@@ -35,6 +35,7 @@ files:
|
|
|
35
35
|
- README.md
|
|
36
36
|
- lib/openreceive.rb
|
|
37
37
|
- lib/openreceive/core.rb
|
|
38
|
+
- lib/openreceive/generated/tables.rb
|
|
38
39
|
- lib/openreceive/keccak256.rb
|
|
39
40
|
- lib/openreceive/nwc_ruby.rb
|
|
40
41
|
- lib/openreceive/rates.rb
|
|
@@ -42,7 +43,14 @@ files:
|
|
|
42
43
|
- lib/openreceive/version.rb
|
|
43
44
|
- skills/debug-openreceive-payment/SKILL.md
|
|
44
45
|
- skills/integrate-openreceive/SKILL.md
|
|
46
|
+
- skills/integrate-openreceive/references/btcpay.md
|
|
47
|
+
- skills/integrate-openreceive/references/django.md
|
|
48
|
+
- skills/integrate-openreceive/references/fastapi.md
|
|
49
|
+
- skills/integrate-openreceive/references/fastify.md
|
|
50
|
+
- skills/integrate-openreceive/references/laravel.md
|
|
51
|
+
- skills/integrate-openreceive/references/next.md
|
|
45
52
|
- skills/integrate-openreceive/references/node.md
|
|
53
|
+
- skills/integrate-openreceive/references/php.md
|
|
46
54
|
- skills/integrate-openreceive/references/rails.md
|
|
47
55
|
homepage: https://openreceive.org
|
|
48
56
|
licenses:
|