DEV Community

HaoJie Luo (Fone)
HaoJie Luo (Fone)

Posted on

Why Stablecoin Checkout Fails After Payment Confirmed (Webhooks, Idempotency, and Refunds)

Most crypto checkout tutorials stop the moment tx.wait() resolves in the browser.

In a real business selling digital goods, SaaS seats, or services, the on-chain confirmation is only half the problem. The bugs that actually cost you support hours happen after the buyer pays: the browser tab closes before the callback fires, a webhook retries and provisions an order twice, or a customer asks for a partial refund and nobody has a clean audit trail.

While building StableIn Payments (a white-label EVM stablecoin payment gateway in Solidity, Foundry, TypeScript, NestJS, and MySQL), four architectural rules made the difference between a fragile checkout widget and a real merchant system.

1. Lock Amounts and Assets on the Merchant Backend

Keep your existing storefront, but never let the browser dictate the checkout price. The storefront button should pass a product identifier; your merchant backend resolves the exact asset, network, quote window, and fee breakdown before the buyer ever signs.

2. Wait for Finality, Then Deliver via Signed Webhooks

Do not fulfill orders from a frontend callback. Index the on-chain payment event on the server, wait for your confirmation threshold, and dispatch a signed webhook to the merchant backend. Verify the signature and compare the paid amount against the locked order before touching fulfillment.

3. Make Merchant Fulfillment Strictly Idempotent

Networks time out. Workers restart. Your payment gateway will deliver the same webhook more than once.

Separate the webhook receipt log from the fulfillment worker, enforce a unique constraint on (order_id, event_type) before granting access, and give ops a safe "replay notification" button so a transient outage never means either a missed delivery or a double-granted license.

4. Design Refunds and Fee Accounting Up Front

If you settle merchant net proceeds directly to the merchant's configured wallet while accounting for platform fees separately, make your refund path explicit from day one: support partial and full refunds back to the original payer funded by the merchant/owner wallet, and keep entitlement revocation cleanly separated in merchant business logic.


Reference & Full White-Label Stack

Top comments (1)

Collapse
 
krusenas profile image
Karolis •

Retry windows are worth checking before launch. Gateways differ a lot on how long they keep re-attempting a failed delivery. If your backend is down longer than that window, a paid order can just never reach you. A replay option is the right safety net, though not every provider has one. I built Webhook Relay, it holds failed deliveries and lets you replay them.