Lightning checkout for static digital products with OpenReceive, NWC, and Netlify Functions
I recently needed a way to sell small digital downloads from a static GitHub Pages site without adding a conventional backend, merchant account, database, or card processor. The store now has a working Lightning checkou
I recently needed a way to sell small digital downloads from a static GitHub Pages site without adding a conventional backend, merchant account, database, or card processor.
The store now has a working Lightning checkout built from three pieces:
- a static HTML form
- a Netlify Function that owns prices and creates invoices
- OpenReceive connected to a receive-only Nostr Wallet Connect (NWC) wallet
The live checkout is used for the SecondWindMC digital products store and the Circuit UI SFX pack. This article is the implementation pattern and the important caveats.
The shape of the checkout
The static page does not mint invoices in the browser. It only submits a product code:
<form action="https://example.netlify.app/.netlify/functions/lightning" method="post">
<input type="hidden" name="product" value="sound-pack-v1">
<button type="submit">Pay by Lightning</button>
</form>
The serverless function owns the catalog:
const products = {
'sound-pack-v1': {
name: 'Circuit UI SFX Vol. 1',
price: '6.99',
},
};
That matters because the payer must never be trusted to choose the amount.
The function then creates an OpenReceive checkout:
import { createOpenReceive } from '@openreceive/node';
const svc = createOpenReceive({
receive: {
type: 'nwc',
connectionString: process.env.NWC_URI,
},
});
const checkout = await svc.createCheckout({
reference: crypto.randomUUID(),
amount: { currency: 'USD', value: product.price },
memo: `Example store ${product.name}`,
metadata: { product: itemCode },
expirySeconds: 900,
});
OpenReceive returns the payment hash, BOLT11 invoice, amount in millisatoshis, creation time, expiry, and fiat quote. The function renders those as a QR code plus a copyable invoice.
Why receive-only NWC is useful
The wallet connection is the dangerous secret in this design, so the wallet is connected through a receive-only NWC code. In my case the vault is hosted by Rizful. The code can create invoices and inspect incoming transactions, but it is not supposed to spend funds.
That is a useful least-privilege boundary for a serverless checkout. It is not self-custody: the hosted wallet is still custodial until funds are withdrawn. Treat it as operational cash, not long-term cold storage, and keep withdrawal hygiene separate from checkout code.
Payment status is not a client claim
A stateless static store still needs some way to connect a browser session back to the invoice it created. I used a short signed receipt containing:
{
v: 1,
p: itemCode,
h: checkout.paymentHash,
c: checkout.createdAt,
r: checkout.reference
}
The receipt is HMAC-signed with a server-side secret. It is not proof of payment. It only prevents casual tampering with the product code and payment hash while the browser polls for status.
The important verification still happens server-side:
const checks = await svc.reconcilePayments({
attempts: [{ paymentHash, createdAt }],
maxPages: 3,
});
const result = checks.find((x) => x.paymentHash === paymentHash);
if (result?.status !== 'settled') {
return paymentPendingPage();
}
return deliverZip();
That order is deliberate:
- verify the signed receipt,
- ask the wallet for the payment state,
- deliver only after the wallet reports settlement.
Delivery in a serverless response
Large zip files can run into synchronous serverless response limits. The first version of this system hit exactly that problem, so the delivery page downloads large archives in verified chunks and reassembles them in the browser.
Small archives can be returned directly. Large archives are chunked; each chunk is still gated by the same server-side payment verification.
What this pattern is good for
This is a pragmatic fit for low-friction digital downloads:
- static marketing site
- fixed catalog and fixed prices
- no customer accounts
- automatic delivery after settlement
- minimal infrastructure beyond serverless functions
OpenReceive also supports optional swap providers for USDT, USDC, SOL, and ETH, converted into BTC over Lightning in the merchant wallet. Asset and network availability depends on the configured provider. I have not enabled swaps yet because short/late swap payments introduce refund responsibilities that need a more deliberate UI and operational process.
What it is not
This is not a replacement for a real ecommerce order system.
A store with customer accounts, inventory, taxes, partial payments, subscriptions, refund workflows, or fulfillment reconciliation should use durable order and payment-attempt rows. OpenReceive's normal integrations are designed around that stronger model. The HMAC receipt approach here is intentionally narrow: it is for a tiny fixed digital-download catalog where every checkout attempt can be re-verified against the wallet before delivery.
Current production verification
The deployed checkout has been verified up to the payment step:
- it creates real Lightning invoices and QR checkout pages,
- unpaid invoices correctly remain pending,
- invalid receipts are rejected,
- unpaid delivery attempts do not expose the zip.
I am not claiming a completed end-to-end settled-payment delivery until a real payment is observed. The checkout is live at secondwindmc.github.io if you want to inspect the buyer-facing flow.
Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes β full credit and traffic to the original publisher.