Secure webhook and API notification flow for crypto payments
Back to blog
WebhooksAPIReliability

Webhook idempotency: handling duplicate payment events safely

Why crypto payment gateway webhooks retry, how to verify IPN signatures, and patterns that keep ledger updates exactly once.

MZA Payments team2026-01-28 · Updated 2026-11-10 · 8 min read

Payment webhooks from a crypto payment gateway are at-least-once deliveries. Networks, load balancers, and your own retry logic can cause the same event to arrive twice. Your integration should assume duplicates — not treat them as bugs.

Verify before you mutate

Validate the signature configured on your webhook endpoint before parsing the body into business logic. On MZA Payments, verify X-Mza-Ipn-Signature with your account IPN secret (HMAC-SHA512 of recursively key-sorted JSON). Reject unsigned traffic in production.

Use a stable event identifier

Store the provider event id (or a hash of type + payment id + status) in a deduplication table. If you have already processed that id, return HTTP 200 without changing balances or fulfilling the order again.

Make handlers small and ordered

Separate “record raw event” from “update invoice status” from “fulfill the order.” Each step should be safe to retry independently. A single monolithic handler that ships product on first parse is fragile under retries.

Respond quickly

Acknowledge within a few seconds; defer heavy work to a queue if needed. Slow endpoints cause unnecessary retries that amplify duplicate volume.

Test failure modes before go-live

Register your IPN URL in Dashboard → Webhooks, use Test delivery, and inspect HTTP status in delivery history. Simulate success, slow responses, and intentional 500 errors to confirm your idempotency keys hold.

Telegram bots need the same rules

If your fulfillment grants Telegram VIP access, duplicate webhooks must not create duplicate entitlements — or worse, skip revocation bookkeeping. Use the same idempotency table for bot grants as for website orders.

Production tip

When you promote to live traffic, keep a staging IPN URL for regression tests. The best webhook integrations look boring in production because duplicates are a solved case.

Put this into practice on MZA Payments

Create an account, grab a LIVE API key, and follow the integration guides for invoices, payment links, and IPN verification.

Keep reading

Related articles