services
Get a key

library / Blockchain ideas / Commerce / BI0122

WooCommerce payment matcher

A small service between a WooCommerce checkout and the chain. Give it an order's reference key, the merchant wallet and the total, and it finds the finalized payment, checks the amount, records the match once and tells the store to mark the order processing.

By Carbium · Commerce · BI0122 · updated 2026-11-23

01

Who uses it

A shop on WordPress with WooCommerce wants to take SOL at checkout. The owner does not want to run a node or read an explorer. The order needs to move from pending payment to processing by itself when the money lands, and to stay put when it does not. A React storefront on top of headless WooCommerce has the same need, because only the store's backend ever talks to the chain.

The matcher is the piece in the middle. The store gives it three things per order: a reference key, the merchant wallet and the total in SOL. It answers with a match or with nothing yet. A hackathon team can build the whole loop in a weekend: a checkout page with a QR code, a worker that polls this check, and one call to the WooCommerce REST API to change the order status. All chain reads go to services.carbium.sh under one key, and every one of them is public data.

02

How a payment is matched

At checkout the store creates a fresh public key for the order and saves it in the order's meta. That key is the reference. It goes into the Solana Pay transfer request as the reference parameter, and the customer's wallet adds it to the payment transaction as a read-only account. The reference never signs anything and holds no funds. Its only job is to appear in exactly one payment, so the address index lists that payment under it.

Matching then takes three checks on the transactions listed at the reference. The transaction succeeded, it is newer than the order, and the merchant wallet's lamport balance rose by at least the order total. The balance change comes from the transaction's meta, so it holds for a plain System transfer and for a payment that passed through another program.

WooCommerce statusMatcher resultWhat the store does
Pending paymentno listed transaction at the reference yetkeep showing the QR code and poll again
On holda payment arrived but the gain is below the totalask the customer for the difference
Processinga payment arrived and the gain covers the totalmark paid and start fulfilment
$The match is evidence that the SOL reached the merchant wallet under this order's reference. It cannot say who the customer is.
03

The build

One file on @solana/kit and what Node 24 ships. It is read-only: no private key, nothing signed or sent. Run it with the reference, the merchant wallet and the total in SOL. The order number and the order's creation time come from the environment.

  • Read the three arguments, then ORDER, SINCE (the order's creation time in unix seconds), LIMIT and GAP_MS from the environment.
  • Open orders.db with node:sqlite and create a matches table whose primary key is the signature.
  • List the newest LIMIT signatures at the reference. A signature already stored for this order answers processing again. Skip failed transactions, signatures with no block time, signatures older than SINCE and signatures that settled another order.
  • For each remaining signature, wait GAP_MS between reads, then fetch the transaction with jsonParsed encoding.
  • Compute the merchant wallet's gain from the pre and post balances. When it covers the total, store the signature against the order and stop.
  • Print the verdict the store reads: processing, or on hold with the shortfall, or nothing yet.
main.ts
// BI0122 · WooCommerce payment matcher// https://carbium.sh/library/blockchainideas/woocommerce-payment-matcher// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.// SPDX-License-Identifier: MITimport { DatabaseSync } from "node:sqlite";import { address, createDefaultRpcTransport, createSolanaRpcFromTransport } from "@solana/kit";const key = process.env.CARBIUM_KEY ?? "";const [reference, merchant, amount] = process.argv.slice(2);const due = Math.round(Number(amount) * 1e9); // order total in lamportsif (!key || !reference || !merchant || !(due > 0)) {  console.error("Set CARBIUM_KEY, then run: node main.ts <reference key> <merchant wallet> <order total in SOL>");  process.exit(1);}const order = process.env.ORDER ?? "1042";const since = Number(process.env.SINCE ?? 0); // unix seconds when the order was createdconst LIMIT = Number(process.env.LIMIT ?? 3);const GAP_MS = Number(process.env.GAP_MS ?? 4500); // 50 cells per call: one call per 4.5 s fits Free's 0.24 req/sconst rpc = createSolanaRpcFromTransport(  createDefaultRpcTransport({    url: process.env.CARBIUM_RPC_URL ?? "https://services.carbium.sh",    headers: { "x-api-key": key },  }),);type Tx = {  meta: { preBalances: (number | bigint)[]; postBalances: (number | bigint)[] } | null;  transaction: { message: { accountKeys: { pubkey: string }[] } };};const db = new DatabaseSync("orders.db");db.exec("CREATE TABLE IF NOT EXISTS matches (signature TEXT PRIMARY KEY, order_id TEXT, lamports INTEGER)");const claimed = db.prepare("SELECT order_id FROM matches WHERE signature = ?");const store = db.prepare("INSERT OR IGNORE INTO matches VALUES (?, ?, ?)");const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms));async function main() {  const sigs = await rpc.getSignaturesForAddress(address(reference!), { limit: LIMIT, commitment: "finalized" }).send();  console.log(`${sigs.length} signatures at the reference`);  let reads = 0;  let short = 0;  for (const s of sigs) {    const owner = claimed.get(s.signature)?.order_id;    if (owner === order) {      console.log(`order ${order}: processing, ${s.signature.slice(0, 8)} already recorded`);      return;    }    if (s.err !== null || s.blockTime === null || Number(s.blockTime) < since || owner !== undefined) continue;    if (reads++) await sleep(GAP_MS);    try {      const tx = (await rpc        .getTransaction(s.signature, { commitment: "finalized", encoding: "jsonParsed", maxSupportedTransactionVersion: 1 })        .send()) as unknown as Tx | null;      if (!tx?.meta) {        console.log(`${s.signature.slice(0, 8)} not readable, skipped`);        continue;      }      // The payment is whatever the merchant wallet gained in this transaction.      const at = tx.transaction.message.accountKeys.findIndex((k) => k.pubkey === merchant);      const gain = at < 0 ? 0 : Math.max(0, Number(tx.meta.postBalances[at]) - Number(tx.meta.preBalances[at]));      if (gain >= due) {        store.run(s.signature, order, gain);        console.log(`order ${order}: processing, ${s.signature.slice(0, 8)} paid ${gain / 1e9} of ${due / 1e9} SOL`);        return;      }      short = Math.max(short, gain);    } catch (e) {      console.log(`${s.signature.slice(0, 8)} failed: ${e instanceof Error ? e.message : e}`);    }  }  if (short > 0) console.log(`order ${order}: on hold, short by ${(due - short) / 1e9} SOL`);  else console.log(`order ${order}: pending payment, nothing matched yet`);}main().catch((e) => {  console.error(e instanceof Error ? e.message : e);  process.exit(1);});

run: CARBIUM_KEY=<YOUR_KEY> ORDER=1042 node main.ts <REFERENCE_KEY> <MERCHANT_WALLET> 0.05

The listing and the read both run at finalized, since a move to processing starts fulfilment and is awkward to undo. A call that left commitment out would run at confirmed under @solana/kit. That level suits a progress indicator on the checkout page and is a poor fit for shipping goods.

The key on signature keeps one payment from settling two orders. If two orders share a reference by mistake, the payment's signature is already stored under the first order, so the second order skips it and stays pending. A worker that polls the same order again after a failed status call gets processing back from the stored row. Passing 1 as maxSupportedTransactionVersion matters too, because mainnet carries v1 transactions and a wallet may send one. Each transaction is read inside its own try, so a failing read prints its message and the loop goes on.

04

What it costs

A poll is one getSignaturesForAddress call at the reference, 50 cells. It finds nothing for most of an order's life, so waiting costs that listing and no more. The one getTransaction read, also 50 cells, happens when a payment shows up. Limits belong to the account, so the store's other tools on the same keys draw from one shared budget.

PlanListing rategetTransaction ratePending orders polled every 5 s
Free ($0)0.24 req/s0.24 req/s1
Dev ($20)1.2 req/s1.2 req/s6
Business ($250)100 req/s5 req/s500
Pro ($500)500 req/s25 req/s2,500

The last column divides the listing rate by the 0.2 req/s that one order polled every 5 seconds draws. On Free, one open checkout at a time fits, so a real shop starts on Dev. The getTransaction column caps how many matches can settle per second, which only matters on a sale day. Credits meter the same calls: Free starts with 500K once, Dev adds 10M a month, Business 50M and Pro 200M.

05

What to add next

  • The WooCommerce call. When the matcher says processing, send PUT /wp-json/wc/v3/orders/<id> with the status set to processing and the signature in a note, using WooCommerce's own REST keys. A WordPress plugin can run the same logic in PHP by calling the JSON-RPC endpoint directly.
  • Instant status. Open wss://services.carbium.sh with the key as ?api-key= and send logsSubscribe with a mention of the reference. Opening costs 25 credits, and each notification carries a signature to hand to the same reader.
  • Prices in dollars. Fix the SOL amount when the order is created and store it in the order meta, so the total the matcher checks never moves. Solana Pay confirmation covers the reference flow in more depth.
  • Token checkouts. List at the reference as before, then compare the token balance rows in meta instead of lamports. The merchant's token account is the one to watch, and a wallet can own more than one for a mint.
  • A second storefront. Shopify Solana Pay orders shows the same matching behind a different store.
06

Where it ends

  • History is the 30-day address index at most. An order older than that cannot be matched again, so keep orders.db and the order meta as the record.
  • The listing reads only the newest LIMIT signatures (3 by default). A reference should hold one payment, so that is enough, and a reference that somehow collects more needs a higher LIMIT.
  • The code counts SOL only, and it checks what the merchant wallet gained with no look at who sent it. A customer who pays the right amount to the wrong order's reference matches the wrong order.
  • If the merchant wallet also pays the network fee in that transaction, the gain is net of the fee and can read short by at least the 5,000-lamport base fee. Customers pay from their own wallets, so this is rare.
  • A merchant wallet with no balance yet needs the rent-exempt minimum in its first payment, or the transfer fails and nothing is listed as paid.
  • Refunds are not tracked. Issue them from WooCommerce and record them there.
  • A listed signature can read as null for an older transaction, and the code prints it and skips it. A signature with no block time is skipped without a line. Both get another try at the next poll.
07

When it goes wrong

what goes wrongwhat to do
The customer paid and the order stays pending payment.Check the transaction on an explorer for the reference key. If the wallet dropped the reference parameter, no listing at that key will ever show the payment. Match it by hand and fix the QR code's URL.
getTransaction answers -32015.The call left out maxSupportedTransactionVersion or set it to 0, and the payment is a v1 transaction. Pass 1 on every getTransaction call in code you write.
A paid order reads on hold by a few thousand lamports.The merchant wallet paid the network fee in that transaction, so its balance change is net of it. Accept a small tolerance in the check, at least the 5,000-lamport base fee, or have the customer pay the fee.
A signature lists and then getTransaction returns null.The address index reaches below the validator's ledger floor, so an old signature can list and read as null. The code prints it and skips it. Match new orders on their newest signatures.
The second order with the same reference never matches.The signature already settled the first order, and the primary key blocks a second use. Create a new reference per order and never reuse one.
The run stops with a clear message instead of output.The key or an argument is missing. Set CARBIUM_KEY and pass the reference, the merchant wallet and the total in SOL.
08

Questions

Does this work with a React checkout instead of WordPress?

Yes. The matcher only needs an order id, a reference, the merchant wallet and a total, so any storefront that can call a small backend can use it. Keep the key on the server and never in browser code.

How often should the store poll?

Every 5 seconds per open checkout is enough while the customer is watching the page, and a slower poll such as 30 seconds fits a pending order they closed. For instant status, subscribe to the reference and run the reader on each notification.

Why a reference key per order and not one address per order?

A reference needs no funds and no rent, and the customer pays to your single merchant wallet. One wallet means one balance to sweep and reconcile, while the reference still ties each payment to one order.

How does the matcher treat an overpayment?

The code treats a gain at or above the total as a match, so the order moves to processing. Record the difference in the order note and refund or credit it from WooCommerce.