Building a Crypto Payment Processor: Lessons From PayGateNow
Nine engineering lessons from building PayGateNow, a non-custodial crypto checkout for WooCommerce: states, callbacks, confirmations, time and logging.

Short answer
Treat a crypto payment processor as a state machine with money attached. Decide who holds the funds first, confirm payments from chain data rather than the browser, make every notification safe to repeat, and keep confirmation rules as settings per network.
In this article
Key points
- PayGateNow is a non-custodial crypto checkout for WooCommerce, so payments go straight to the merchant's own wallet and there is no pooled balance to protect.
- The browser returning to a thank-you page is not proof of payment, so an order should become paid only after the payment is verified on the network.
- WooCommerce says to call payment_complete() instead of setting the status by hand, and to use on-hold when a payment cannot be verified automatically.
- WP-Cron runs on page loads and can run late, so payment rules should compare timestamps instead of depending on a job firing at an exact moment.
- Bitcoin and Ethereum reach certainty differently, so confirmation rules belong in settings per network and order size.
PayGateNow is one of my five ventures. It is a non-custodial crypto checkout for WooCommerce: the customer pays straight to the merchant’s own wallet, and the processor does not sit in the middle holding the money. Building it taught me that a payment processor is mostly a state machine with money attached, and that the happy path is the smallest part of the job.
This post is a set of general engineering lessons. They come from building a checkout plugin for WooCommerce, but most apply to any payment code. I have kept out numbers and stories, because the lessons do not need them. Where I rely on a fact about WooCommerce, WordPress or a blockchain, I take it from the official documentation and link it.
Lesson 1: Decide who holds the money before you write code
Every other design choice follows from this one. A custodial processor receives the customer’s payment, holds it, and pays the merchant later. That makes refunds, holds and reporting easy to build, and it makes the processor a place where other people’s money sits. A non-custodial design sends the payment directly to the merchant’s wallet. I explain the model in my post on non-custodial checkout.
The trade-off is honest and worth stating plainly:
| Question | Custodial processor | Non-custodial checkout |
|---|---|---|
| Who holds customer funds? | The processor, until it pays out | Nobody in between: the payment lands in the merchant’s own wallet |
| What can go wrong with a pooled balance? | A great deal, because everyone’s money is in one place | That risk does not exist, because there is no pool |
| Who sends a refund? | The processor can do it from the balance | The merchant sends a new payment, because a transaction cannot be reversed |
| What does the plugin have to prove? | That the balance is right | That each payment reached the right address, for the right amount, on the right network |
I chose the second model because it removes the largest risk in the whole business. But it moves work to other places. The merchant handles refunds. The software has to prove, from chain data, that each payment arrived correctly. That leads to the next lesson.
Verify from the chain and draw the states first
Lesson 2: The chain is the source of truth, not the browser
In a WooCommerce gateway, the customer is sent through checkout and returned to a thank-you page. It is tempting to treat that return as proof of payment. It is not. The browser can be closed, the page can be reloaded, and the return URL can be visited by anyone who has the link.
The WooCommerce payment gateway API shows the right shape. A gateway’s process_payment method returns a result and a redirect URL. For payment systems that notify the shop from outside, it describes API callbacks: a URL carrying a wc-api parameter, handled by a hook named after the gateway class. The customer’s browser is one path. The notification from a system that can verify the payment is another, and that one decides the order’s fate.
So the rule I hold the build to is: an order becomes paid only when the payment has been verified against the network, never because a customer reached a page. Everything on the checkout page is a message to the customer. It is not evidence.
Lesson 3: Model payments as states, then map them to order statuses
A card payment is mostly yes or no. A crypto payment moves through stages. It is waiting, then seen, then confirming, then final. It may also be short, late, sent on the wrong network or abandoned. If you reduce that to paid or unpaid, you will mishandle most of the in-between cases.
I write the states first, on paper, and only then connect them to WooCommerce. The gateway API gives clear guidance on the mapping:
- If the payment cannot be verified automatically, set the order to on-hold with a note.
- When the payment is complete, call
payment_complete()on the order, not a manual status change. WooCommerce then sets the right status, processing or completed, and handles stock. - If an existing order’s payment fails, mark it failed.
- Use order notes to record what happened without changing the status.
I go through the awkward states in my edge cases post. The lesson for builders is that the table of states and statuses is the product. The interface is just a window onto it.
A crypto checkout is a state machine with money attached, so draw the states before you draw the screens.
Own-ur-Rehman Sheikh
Lesson 4: Make every notification safe to receive twice
Any system that sends notifications will sometimes send the same one again. Networks retry, queues redeliver and people reload pages. If receiving a notification twice can mark an order paid twice, release stock twice or send two emails, you have a bug waiting for the wrong moment.
The fix is a habit, not a clever trick. Before acting on a payment notification, read the order’s current state. If the order is already paid, record the duplicate in a note and stop. If it is in a state that cannot move to paid, such as cancelled, flag it for a person. The same applies to your own checks: a job that confirms payments should be able to run again and again without changing the result.
The WooCommerce guide supports the approach indirectly. It tells you to let payment_complete() do the status and stock work rather than doing it by hand, which means the state change lives in one place. One place is easier to guard than five.
Confirmations and time
Lesson 5: Do not hard-code one idea of “confirmed”
Different networks reach certainty in different ways, and a single rule will be wrong somewhere. The Bitcoin project’s page You need to know says a transaction becomes irreversible gradually, with each confirmation making it harder to reverse. It calls zero confirmations safe only if you trust the payer, and six the minimum recommendation for high-value transfers. Ethereum.org’s page on transactions describes a different path: pending, then included in a block, then justified and finalized.
The software lesson is to keep the confirmation rule as a setting per network and per order size, not a constant buried in code. A merchant selling a low-value download and one selling expensive goods should not be forced into the same wait. I discuss how I choose in the edge cases post, and I mark those thresholds there as policy choices, not network rules.
Lesson 6: Time is a hazard, so do not trust the clock
Invoices expire. Prices move. Payments arrive late. Each of those depends on time, and time in a WordPress plugin is less exact than most developers expect. The WordPress plugin handbook on cron says WP-Cron works by checking its list of scheduled tasks on page loads. It does not run constantly like a system scheduler, so a task can run later than planned. The page’s own example is a task set for 2:00 PM that waits until a page load at 5:00 PM.
That has a direct design consequence. Never rely on a scheduled job firing at an exact moment to decide whether a payment counts. Decide by comparing the payment’s own timestamp with the invoice’s expiry when the payment is checked, so a late job cannot turn a valid payment into a rejected one. Scheduled jobs are good for housekeeping and for catching up. They should not be the thing that defines the rules.
Lesson 7: Work with the platform, not around it
A plugin lives inside someone else’s shop. The more it respects the platform, the fewer surprises the merchant gets.
Order storage
WooCommerce’s page on High-Performance Order Storage says orders can live in dedicated tables instead of the posts tables. It is enabled by default for new installations from WooCommerce 8.2, and developers must declare compatibility. For extensions from outside the Marketplace, the switch is disabled while an incompatible one is active. For a payment plugin, that means declaring compatibility and reading and writing orders through the order objects, not through assumptions about where the data sits.
Output and input
A checkout page shows addresses, amounts and instructions that a customer will copy. The WordPress guidance on escaping says to escape output as late as possible, ideally as it is printed, using functions such as esc_html(), esc_attr() and esc_url(). I treat every value that reaches the page as untrusted, including values from my own database. A wrong character in a payment address is not a cosmetic bug.
Lesson 8: Leave a record you can read at 2 a.m.
When a customer says “I paid”, you need to answer in a minute. That is only possible if every important event leaves a trace on the order: the invoice amount, the network, the address shown, when a payment was seen, how many confirmations it had, what rule was applied and what the system did. WooCommerce order notes exist for this. The gateway guide says to use them to log information without changing the status.
I keep notes short and factual. A note such as “Payment seen, 1 confirmation, waiting for 3” is useful. A note that dumps raw data is not. And notes must never contain secrets. In a non-custodial design the software never needs the merchant’s private keys, and I would not want it near them.
Lesson 9: Keep the scope small and the rules visible
The temptation in payments is to add features: more coins, more networks, more modes. Each one multiplies the states you must test. I would rather support fewer options and prove they work than list many and hope. A short list of tested networks, written clearly at checkout, beats a long list of half-checked ones. The rules that remain should be visible to the customer, because a customer who understands the rules makes fewer mistakes.
The same thinking applies to the friction at the end of any funnel. Rank Ray’s guide on cart abandonment recovery is about ecommerce in general, but its point holds for crypto too: every unclear step costs sales. A payment page that explains the amount, network, address and status clearly is both a safety feature and a conversion feature.
The short version
If you are building anything that moves money, here is the list I would check your design against:
- Decide who holds the funds, and accept what follows from it.
- Treat the network, not the browser, as the source of truth.
- Draw the payment states first and map them to order statuses using the platform’s own methods.
- Make every notification and job safe to run twice.
- Keep confirmation rules as settings per network and order size.
- Judge time from timestamps, not from when a scheduled job happens to run.
- Declare compatibility, use the order objects and escape every output.
- Leave a clear, short record on every order.
- Support fewer options, and test each one with a real payment.
None of this is glamorous. It is mostly about refusing to guess. In a system where a transaction cannot be reversed, every guess is paid for by somebody, so the best code is the code that checks first.
FAQ
What is a non-custodial crypto payment processor?
It is one where the customer's payment goes directly to the merchant's own wallet, so the processor does not hold customer funds in between. PayGateNow works this way for WooCommerce.
How should a WooCommerce gateway mark an order as paid?
WooCommerce's gateway guide says to call payment_complete() on the order rather than setting the status directly. WooCommerce then sets processing or completed and handles stock. Use on-hold when a payment cannot be verified automatically.
Why not trust the customer returning to the thank-you page?
The page can be reloaded or opened by anyone with the link, and a customer can close the browser before it loads. Verify the payment against the network instead.
Is WP-Cron reliable for timing invoice expiry?
Not for exact timing. The WordPress handbook says WP-Cron checks scheduled tasks on page loads, so a task can run later than planned. Compare the payment's own timestamp with the invoice expiry when you check it.
Do WooCommerce payment plugins need to support HPOS?
WooCommerce says developers must declare compatibility with High-Performance Order Storage, and it is enabled by default for new installations from WooCommerce 8.2. Read and write orders through the order objects.



