This is the full file; follow it from Step 0.

# OpenReceive agent directions (Magento)

```sh
# READ THIS FIRST: this file is 17 KB and a summary drops required steps. Download it whole:
curl -fsSL https://openreceive.org/agent-directions/magento/full.md
# If your tool cuts long output, save it and read it in parts: curl -fsSL -o /tmp/openreceive-directions.md https://openreceive.org/agent-directions/magento/full.md
# Skip the download only if you already have all of it: pasted, read from disk or fetched raw.
```

**Step 0 in brief** (Step 0 below has the details):

- Before installing or editing anything, ask the user for a receive-only NWC code. One question per message.
- Next ask for the LSC code. If the user wants stablecoins, USDT, USDC, ETH, SOL or crypto, do not ask yes/no first.
- The user only pastes codes here: no command, no admin page. If you will not take one in chat, see Step 0.
- Store each code yourself as Step 2 says. Never put a code in a shell command.
- Do not suggest rotating or revoking a code because it was pasted here.
- Setup is done only when the NWC code is saved, and the LSC code is saved or the user said "Bitcoin only".

These directions describe OpenReceive 0.6.8.

Install and configure the OpenReceive payment module in the Magento Open
Source 2.4 store you are working in. Preserve its theme, customers, products,
orders and prices. The module is a Composer package
(`openreceive/magento2-module`) that brings a prefixed copy of the PHP engine
with it (`openreceive/magento2-engine`): do not clone the OpenReceive
repository, and do not write payment code of your own.

The one required credential is a receive-only NWC code (Nostr Wallet Connect):
a string from the merchant's wallet that can create invoices and read their
status, and cannot spend. A swap provider (an "LSC" code) optionally lets
customers pay with USDT, USDC, ETH or SOL instead; the provider converts the
payment to BTC over Lightning in the merchant's connected wallet. Available
assets and networks depend on the provider.

Run every `bin/magento` and `composer` command below in Magento's folder, the
way this project already runs them: inside its PHP container when a compose
file runs the store (`docker compose exec -T <php service> bin/magento …`), as
the web server's user, never as root.

## Step 0 — ask for the two codes, one question at a time

Before anything else, check one thing: whether OpenReceive is already
installed (`bin/magento openreceive:doctor`; without the module it answers
that the command is not defined, which means not installed). If it exists, it
prints `NWC_URI: set` or `unset` (likewise `LSC_URI_PRIMARY`), never the
values. A code that is already set is not asked for again; if both are set,
skip to Step 3.

Otherwise your next action is a question to the user. Do not install the
module, edit Docker files or search anywhere else before asking it. Do not
read `app/etc/env.php`, Magento's configuration, deploy config, container
environments or other projects looking for a code: a new install has neither
code yet.

The user never runs a command. They paste each code into this chat; you
store it. That is the supported path: do not ask them to run the save
command themselves, and do not tell them to revoke or replace a
code because it was pasted here. Ask one question per message.

If you will not take a code pasted in chat, end that same message with this
in place of "Paste the code here": "Save the code alone in
`/tmp/openreceive-nwc`, then reply saved." (`/tmp/openreceive-lsc` for the
swap code). Step 2 then reads that file in place of `/tmp/openreceive-code`
and deletes it. Ask once per code: if the file is missing after their reply,
do not ask again; say which file is missing, and stop. Never print it.

1. **First message — the NWC code, and nothing else.**

   > To receive payments I need a receive-only wallet code. In Rizful: open
   > the menu, tap NWC Codes, then tap Copy receive-only code
   > (https://openreceive.org/get_a_nwc_code_to_receive_payments). If you would
   > rather run your own wallet, Alby Hub works too: Connections → Add
   > Connection → Read Only. Paste the code here and I will store it.

2. **When they paste it.** If it does not start with `nostr+walletconnect://`,
   ask them to copy the receive-only code again. Otherwise do not repeat it:
   reply only that you have it, then ask the next question. You store it in
   Step 2.
3. **Second message — swaps.** If the user asked for stablecoins, USDT, USDC,
   ETH, SOL or coins other than Bitcoin (as in "Bitcoin and stablecoin
   payments"), this message IS the walkthrough below: do not skip it, and do
   not ask yes or no first. Otherwise ask whether customers should also be
   able to pay with USDT, USDC, ETH or SOL, then give the walkthrough. The
   walkthrough:

   > Go to https://lightning-swap.com, sign in for API keys, create a key, and
   > copy the whole URI (https://openreceive.org/set_up_swap_provider). Paste
   > it here and I will store it — or say "Bitcoin only" and I will continue
   > without it.

   Mention FixedFloat only if they already use it.
4. **When they paste it.** If it does not start with
   `lightning+swapconnect://`, ask them to copy it again. Swaps are now on,
   so keep the route back (the swap non-negotiable below).

Do not report setup as complete until the NWC code is saved, and the LSC code
is saved or the user said "Bitcoin only". Never invent a placeholder code.

## Step 1 — install the module

The module needs Magento Open Source 2.4.7 or later with the Luma checkout, on
64-bit PHP 8.2+ with `gmp` and `sodium` (`php -m` must list both, where the
store runs). Without one of them, say which PHP extension is missing and
stop: installing PHP extensions is the merchant's decision. A store on Hyvä
Checkout is not supported yet: say so and stop.

```sh
composer require openreceive/magento2-module
bin/magento module:enable OpenReceive_Payment
bin/magento setup:upgrade
```

In production mode, also run `bin/magento setup:di:compile` and
`bin/magento setup:static-content:deploy`, as after any module. If the
project's own rules (its `AGENTS.md`, contributing guide) forbid running
`setup:upgrade`, ask the owner and wait.

## Step 2 — store the codes

Store each code yourself, one per command, and never as a shell argument:

1. Write the code with your file-editing tool, not a shell command (no
   `echo`, `printf` or heredoc), to a new file outside Magento's folder, such
   as `/tmp/openreceive-code`.
2. Run `bin/magento openreceive:configure --nwc-uri=- < /tmp/openreceive-code`.
   In Docker: `docker compose exec -T <php service> bin/magento openreceive:configure --nwc-uri=- < /tmp/openreceive-code`.
   For the swap code, use `--lsc-uri-primary=-`.
3. Delete the file (`rm /tmp/openreceive-code`), whether the command passed
   or not.

The command asks the wallet first and saves the code, encrypted with
Magento's key, only when the wallet answers as receive-only; a failure saves
nothing. If it reports spend methods such as `pay_invoice`, ask the user for
a receive-only code again. Saving the wallet code also turns the payment
method on. Never write a code into `app/etc/env.php`, `core_config_data` or
any file in Magento's folder yourself.

Then run `bin/magento openreceive:doctor`. It names any failed check; fix it
before going on.

## Step 3 — hand over, then stop

You cannot pay an invoice: the code is receive-only. Do not pay, settle or
mark an order paid, and do not look for a way to (a wallet control port, a
test endpoint, another wallet). If the user wants a real settlement test, they
place an order and pay it on its pay page from their own wallet; afterwards
the order reads "Processing".

Setup ends here. Once doctor is clean, your last message starts "Setup is
finished" and has at most six short lines: "Open <store url>, add a product
and choose Bitcoin Lightning at checkout: placing the order opens the payment
page", the methods the checkout offers (Bitcoin, plus USDT, USDC, ETH and SOL
when the swap code is saved), one line that Magento's cron must run
(`bin/magento cron:install` if it does not already), and one line of what to
look at. Do not mention a minimum or say a coin will not work: a provider
minimum depends on the order total. Do not list what you changed or what
doctor checked. Send nothing after it.

A customer who pays and closes the page is settled by the module's cron job,
which needs Magento's own cron. Do not install crontab entries, containers,
services or workers yourself: name the command in your last message.

## Non-negotiables

- Never print, log or commit a code, never put one in a shell argument, and
  never write one into source files, `app/etc/env.php`, the database or
  browser code. Doctor's set/unset is all you report.
- Do not suggest rotating, revoking or replacing a code because it was pasted
  into this chat; that is the supported path.
- Work only in this store. Never read or run anything from another project or
  directory on this machine (its `node_modules`, tools or source), for any
  reason. A browser, Playwright, hand-made calls to the checkout's routes,
  database queries and reading the module's source are not part of setup:
  when doctor fails, report its output.
- Receive-only NWC is required. Never get past the preflight with a code that
  can spend.
- The module owns only its two payment tables in Magento's database and its
  settings under `payment/openreceive`. Magento owns customers, orders,
  prices, invoices and email. Do not add an external payment database or
  custom fulfillment code, and do not edit Magento's own files or the theme.
- IF SWAPS ARE ON, KEEP THE ROUTE BACK. A deposit that arrives short or late
  becomes refundable, and the customer claims it later from the order's pay
  page. Keep the module installed while swap payments may still need a
  refund. https://openreceive.org/guides/swap-refunds.md
- A receive-only wallet cannot send refunds. Refund a settled payment manually
  from the wallet.

## Further reading

- [Magento Quickstart](https://openreceive.org/guides/quickstart-magento.md)
- [Automated Swaps](https://openreceive.org/guides/automated-swaps.md)
- [Swap Refunds](https://openreceive.org/guides/swap-refunds.md)
- [Lightning Swap Connect URI](https://openreceive.org/guides/lightning-swap-connect.md)
- [Security](https://openreceive.org/guides/security.md)
- [Currencies](https://openreceive.org/guides/currencies.md)
- [Price Feeds](https://openreceive.org/guides/price-feeds.md)

---

## The quickstart, in full

Inlined verbatim so this file needs no network access. Steps 0–3 above are the setup and this is their reference: where the two differ, the steps win, and its admin screens are only for a store with no shell.
The page it comes from is https://openreceive.org/guides/quickstart-magento.

## Magento quickstart

The OpenReceive module adds a payment method to
[Magento Open Source](https://business.adobe.com/products/magento/open-source.html):
the customer picks "Bitcoin Lightning" at checkout, places the order, and pays
on the order's own pay page, straight into your own wallet. With a swap
provider, the same page also takes USDT, USDC, SOL and ETH, which the provider
converts to BTC over Lightning into the same wallet. The settled payment
invoices the order and moves it to Processing, as Magento's offline capture
would.

Magento keeps owning customers, orders, prices and fulfilment. The module
keeps its payment attempts in two tables of Magento's own database
(`openreceive_payments` and `openreceive_meta`, declared in its
`etc/db_schema.xml`, so `setup:upgrade` creates them).

Requirements: Magento Open Source 2.4.7 or later with the Luma checkout, on
64-bit PHP 8.2 or later with GMP and sodium, and Magento's cron
(`bin/magento cron:install`). Hyvä Checkout is not supported yet. Already run
BTCPay Server? [Magento via BTCPay Server](https://openreceive.org/guides/magento.md) is the other route.

### Install the module

```sh
composer require openreceive/magento2-module
bin/magento module:enable OpenReceive_Payment
bin/magento setup:upgrade
```

Composer installs a second package with it, `openreceive/magento2-engine`:
the OpenReceive engine and its libraries with every namespace prefixed,
because Magento 2.4 locks older versions of libraries the engine needs. In
production mode, run `bin/magento setup:di:compile` and
`bin/magento setup:static-content:deploy` as after any module.

Run every `bin/magento` command as the web server's user, never as root.

### Configure the wallet

Save a receive-only NWC code
([get one](https://openreceive.org/get_a_nwc_code_to_receive_payments)) from
the command line, reading it from a file so it never appears in a shell
argument:

```sh
bin/magento openreceive:configure --nwc-uri=- < /path/to/code-file
```

Or paste it under **Stores > Configuration > Sales > Payment Methods >
Bitcoin Lightning (OpenReceive)** and set **Enabled** to Yes. Either way the
module asks the wallet first, and saves the code encrypted with Magento's own
key only when the wallet answers as receive-only. A code that can also spend
is refused. The optional swap provider code goes in the same place
(`--lsc-uri-primary=-`;
[set up a swap provider](https://openreceive.org/set_up_swap_provider)).

The codes are store-wide (the default scope).

### The cron job

Magento's cron runs the module's `openreceive_reconcile` job every minute. It
settles payments whose customer closed the pay page before the payment
arrived. Make sure Magento's cron is installed (`bin/magento cron:install`);
`bin/magento openreceive:reconcile` runs the same pass by hand.

### Check it

```sh
bin/magento openreceive:doctor
bin/magento openreceive:test-invoice <order id>
```

The doctor checks the install and prints each code as set or unset, never the
value. `test-invoice` makes the Lightning invoice for an order waiting for
its payment, through the pay page's own route, and prints the pay page's
link.

### How a payment works

1. Placing the order leaves it in **Pending Payment** and holds back the
   order email.
2. The browser goes to the pay page,
   `/openreceive/pay?order=<id>&token=<token>`. The customer can come back to
   it from the order's page in their account, or the guest order lookup,
   until the order is paid. The success page links it too.
3. The checkout on that page talks to the engine's JSON routes under
   `/openreceive/`. Writes need the session's Magento form key; the engine
   refuses cross-site requests and anything but JSON. The invoice is for the
   order's grand total in the order's currency, converted at the current BTC
   price, and only while the order is Pending Payment.
4. When the payment settles, the order is invoiced (offline capture, the
   payment hash as the transaction id) and moves to **Processing**, in the
   same database transaction as the payment record. The order and invoice
   emails go out after that.

Magento cancels a Pending Payment order after "Pending Payment Order
Lifetime" (480 minutes by default). The module keeps an order out of that
cleanup while one of its payments may still settle, so a payment never lands
on an order Magento canceled on its own. A payment that settles on an order
the merchant canceled by hand is recorded on the order as a comment and
listed by `openreceive:doctor`; the order stays canceled.

### Refunds and removal

The receive-only wallet cannot send refunds. Send a refund from your own
wallet, then record a credit memo in Magento. A customer whose swap deposit
never converted reclaims it from the order's pay page, while the order is
unpaid. If you turn on swaps, you commit to keeping that path available. See
[swap refunds](https://openreceive.org/guides/swap-refunds.md).

Disabling the payment method hides it at checkout. Removing the module keeps
the two tables, which are a record of payments received.

### Tested, and not tested

Tested on 2026-11-28 with Magento Open Source 2.4.8-p3 in production mode,
MariaDB 11.4 and OpenSearch 2.19 in Docker, and a test wallet on a live relay:
a guest order placed through the REST API, left in Pending Payment with its
email held; a write without the form key refused and a wrong pay-page token
refused; the pay page making the invoice; the payment settling; and the order
reading Processing, with a paid invoice carrying the payment hash. In
Chromium, a Luma checkout placed a second order, went to the pay page, and
reached Processing the same way. The cleanup of expired Pending Payment
orders and a hand-canceled order behaved as above.

Swaps were tested the same way against a test swap provider, a fake of the
provider's API that moves no funds, saved with `openreceive:configure`. In
Chromium, a guest picked USDT on Solana on an order's pay page and the deposit
screen showed one amount, the USDT to send. The provider completed the swap,
the swap's Lightning invoice settled, and the order reached Processing with a
paid invoice carrying the swap's payment hash. A second order's swap, which
the provider reported underpaid, was refunded to a Solana address from the
checkout, and that order stayed in Pending Payment.

Not tested: a real swap provider, the other swap coins and networks, Adobe
Commerce, multi-store installs with different currencies, Hyvä Checkout,
Magento 2.4.7, PHP 8.2, and updating from an older release of the module.
