OpenReceive for Symfony

Accept Bitcoin & Stablecoin Payments With Symfony

Install the Symfony bundle, generate the config, the route import, a host service and a Doctrine migration, then render the checkout in a Twig template of your existing app. Symfony keeps security and orders; OpenReceive owns only payment attempts and settlement.

Package

Copy agent directions — Paste into Claude Code, Codex or Cursor to add OpenReceive to your Symfony app.

Why OpenReceive

Try the checkout your customers will see

In a Symfony app this checkout is one <openreceive-checkout> tag in a Twig template, talking to the routes the bundle mounts at /openreceive. The repository's Symfony starter is a small shop built the same way. The live demo needs JavaScript: open the OpenReceive home page.

Six steps, real code

Requires PHP ≥ 8.2 (64-bit), Symfony 6.4, 7 or 8, Doctrine DBAL, ext-gmp.

1. Get a receive-only NWC code — get one here. It can issue invoices and watch for payment, and it can never spend from your wallet.

2. Get an LSC code for swaps (optional) — from a swap provider, only if customers should be able to pay in USDT, USDC, ETH or SOL.

3. Set the environment variables — NWC_URI (required) and LSC_URI_PRIMARY / LSC_URI_BACKUP (optional) in the environment of your Symfony server process; see Environment variables.

4. Install

composer require openreceive/symfony-bundle

5. Wire OpenReceive — quoted from the Symfony quickstart.

<?php

namespace App\OpenReceive;

use App\Repository\OrderRepository;        // YOUR repository — it could be named anything.
use OpenReceive\Host as OpenReceiveHost;
use OpenReceive\PaymentSettlement;
use OpenReceive\Server\AuthorizeContext;
use Symfony\Bundle\SecurityBundle\Security;

final class Host implements OpenReceiveHost
{
    public function __construct(
        private readonly OrderRepository $orders,
        private readonly Security $security,
    ) {
    }

    // Your policy, called before every checkout/payment/swap request.
    //   $context->action    — "checkout.prepare", "checkout.create", "payment.check",
    //                         "swap.quote", "swap.create", "swap.read" or "swap.refund"
    //   $context->request   — the Symfony\Component\HttpFoundation\Request: session,
    //                         cookies and headers, as in a controller
    //   $context->resource  — ['reference' => …, 'payment_hash' => ?] copied from the
    //                         payer's JSON body. It names an order; it does not prove
    //                         this caller owns it. reference is always a validated
    //                         non-empty string (≤200 chars); payment_hash is null except
    //                         on payment.check / swap.read / swap.refund.
    // Return true to allow, false for a 403. Here: only the signed-in customer
    // who placed the order may act on it.
    public function authorize(AuthorizeContext $context): bool
    {
        $order = $this->orders->find($context->reference());
        return $order !== null && $order->getCustomer() === $this->security->getUser();
    }

    // The price for a reference — here, your order id — from your own data; null
    // when there is nothing to pay for (a 404). `value` is a decimal STRING from
    // the order row, never a float and never a request param. `description` is
    // what the payer is buying, in your own words.
    public function amountFor(string $reference): ?array
    {
        $order = $this->orders->find($reference);
        return $order === null ? null : [
            'currency' => 'USD',
            'value' => $order->getTotal(),                 // a decimal string column
            'description' => count($order->getItems()) . ' items',
        ];
    }

    // Runs inside the settlement transaction, only for the order's first settled
    // attempt. The WHERE clause is the lock: a second fulfillment path of yours
    // (admin action, replayed message) updates zero rows and does nothing.
    public function onPaid(PaymentSettlement $settlement): void
    {
        $settlement->connection?->execute(
            "UPDATE orders SET state = 'paid', paid_at = ? WHERE id = ? AND state = 'awaiting_payment'",
            [gmdate('Y-m-d H:i:s', $settlement->paidAt), $settlement->reference],
        );
    }
}

6. Render the checkout

{# templates/order/pay.html.twig #}
<link rel="stylesheet" href="/openreceive-checkout/openreceive-checkout.css" />
<script type="module" src="/openreceive-checkout/openreceive-checkout.js"></script>

<openreceive-checkout reference="{{ order.id }}" resumable></openreceive-checkout>

Full Symfony quickstart · Example app

How it runs

Tested on
PHP 8.2 to 8.4, Symfony 6.4 and 7.4
Databases
PostgreSQL, MySQL 8 and SQLite
Secrets
NWC_URI, and LSC_URI_PRIMARY for swaps, in the server's environment or .env file, never in browser code
Refunds
Refund a settled Lightning payment from your own wallet: the wallet code is receive-only. A swap deposit that never converted goes back to the payer through the checkout's refund form.
Mobile apps
No app SDK. A mobile app opens your checkout page in a browser tab, which the app stores allow for physical goods and real-world services; digital goods need a link-out program.

Practical questions

Which currencies can customers pay with?
Bitcoin over Lightning, always. With a swap provider configured, also USDT on Tron, Solana or Ethereum, USDC on Solana or Ethereum, ETH and SOL, each converted into the same Lightning payment. Automated swaps guide
Where does the Bitcoin go?
Into the wallet behind your NWC code; OpenReceive never holds funds. When an order's first payment settles, the bundle calls onPaid in src/OpenReceive/Host.php inside the settlement transaction, on your Doctrine DBAL connection. Mark the order paid there, and send mail or dispatch a Messenger message from afterPaid, which runs after the commit. Symfony quickstart
What wallet do I need?
Any wallet that issues receive-only NWC (Nostr Wallet Connect) codes, hosted or self-run. The code must be able to create invoices and read their status, and must not be able to spend. Get a receive-only NWC code
What does it cost?
OpenReceive is completely free and open source (MIT). For Bitcoin Lightning payments, every listed NWC provider charges 0% to receive; for stablecoin, ETH and SOL payments, your payer pays the swap provider's fee, not you. See full pricing & fee breakdown
What do I need to deploy?
64-bit PHP 8.2 or later with GMP, sodium and mbstring, Symfony 6.4, 7 or 8 with Doctrine, NWC_URI in .env.local or the server environment, and the generated migration run with bin/console doctrine:migrations:migrate against your existing database. No cron or worker is required: settlement runs on the bundle's routes, and bin/console openreceive:notifications is an optional worker for faster confirmation. Symfony quickstart

Add OpenReceive to your Symfony app

Copy agent directions · Full quickstart · Example app · API reference · Guides

Related

Sylius · Laravel