settlematic
Guides··11 min read·By Keshav Sharma

Webhook Patterns for Crypto Billing: Events, Idempotency, and Reconciliation

Design reliable webhook handlers for crypto billing: payment events, idempotent processing, retry logic, and reconciliation with your accounting stack.

Do this next

Create a crypto invoice

  1. Quote the invoice in fiat.
  2. Client pays USDC, USDT, or EURC.
  3. Funds settle to a wallet you already control.

TL;DR

Subscribe to payment.confirmed and invoice.paid, dedupe by event ID, map to ERP journal entries once, and monitor delivery logs - webhooks beat polling for crypto billing automation.

Settlematic webhook endpoint setup subscribing to invoice and payment events for automation

Webhook patterns for crypto billing are event-driven integration designs that push invoice and payment state changes from your billing platform to your application endpoints in real time, replacing fragile polling of blockchain explorers and dashboard checks. When a client pays a USDC invoice on Solana or an ETH invoice on Base, a well-designed webhook delivers a signed HTTP POST containing invoice ID, transaction hash, amount, network, and confirmation status—allowing your systems to mark orders fulfilled, send receipt emails, and post journal entries automatically.

Why Webhooks Beat Polling for Crypto Payments

Blockchain confirmation times vary by network. Solana finality is sub-second; Ethereum L2s may take seconds to minutes; mainnet Ethereum depends on gas markets. Polling your invoicing dashboard or RPC endpoints on a fixed interval wastes resources and introduces lag between confirmation and business action.

Webhooks invert the model: the billing platform monitors chains continuously and pushes events when state changes. Your handler receives invoice.paid within seconds of confirmation threshold met.

Benefits:

  • Lower latency for fulfillment and client notifications
  • Reduced API load compared to per-invoice polling
  • Cleaner separation between payment verification (platform) and business logic (your app)
  • Audit trail via logged webhook payloads correlated to on-chain tx hashes

Core Event Types for Crypto Billing

A mature crypto invoicing platform emits a lifecycle event stream. Standard events include:

EventTriggerTypical consumer action
invoice.createdInvoice generated with payment addressSync to CRM, send branded email
invoice.viewedClient opened payment pageAnalytics, follow-up automation
invoice.payment_detectedUnconfirmed transfer seen on-chainUI update, optional "processing" email
invoice.payment_confirmedTransfer met confirmation rulesFulfill order, post to QuickBooks
invoice.partially_paidAmount received < invoice totalNotify merchant, hold fulfillment
invoice.overpaidAmount received > invoice totalFlag for manual refund or credit
invoice.expiredPast due date without full paymentArchive, send reminder workflow
invoice.voidedMerchant canceled invoiceRevoke payment page access

Settlematic webhook payloads include invoice metadata, on-chain proof fields, and organization context so handlers can route events in multi-tenant setups.

Webhook Security: Verification First

Never process unsigned webhooks in production. Attackers can POST fake invoice.paid events to open endpoints, triggering fulfillment without payment.

Standard verification patterns:

  • HMAC signature in header (e.g., X-Settlematic-Signature) computed over raw body with shared secret
  • Timestamp tolerance rejecting requests older than five minutes to prevent replay
  • Constant-time comparison of signature strings to prevent timing attacks
  • IP allowlisting as supplementary defense (not sole reliance—IPs change)

Pseudocode flow:

Rotate webhook secrets periodically and support multiple active secrets during rotation windows.

Idempotency: The Non-Negotiable Requirement

Networks retry. Platforms retry. Your load balancer retries. The same invoice.payment_confirmed event with identical event_id may arrive three times. Idempotent handlers guarantee duplicate delivery does not duplicate side effects.

Implementation strategies:

  • Event ID deduplication table: Store processed event_id with unique constraint; skip if exists
  • Idempotency keys on downstream APIs: Pass invoice_id + tx_hash as idempotency key to payment posting endpoints
  • Database transactions: Check paid status before update; use UPDATE ... WHERE status != 'paid'

Without idempotency, duplicate webhooks double-ship products, double-post revenue, or send duplicate receipt emails.

Reconciliation: Matching Webhooks to On-Chain Truth

Webhooks are fast; reconciliation is correct. Month-end close requires your books match blockchain reality. Webhook handlers are the first mile; reconciliation is the last mile.

Reconciliation layers:

  • Webhook ingestion marks invoice paid in operational DB
  • Nightly batch compares webhook-recorded tx hashes against indexer APIs
  • Accounting export pushes confirmed payments to QuickBooks/Xero—see export-crypto-invoice-data-quickbooks-xero
  • Exception queue for partial payments, wrong-chain deposits, and indexer discrepancies

Dual-source verification at the platform level—comparing multiple indexers before emitting payment_confirmed—reduces reconciliation exceptions. Document your handler's assumption: trust webhook after signature verification, verify independently at reconcile time.

Retry Semantics and Dead Letter Queues

Your endpoint will fail—deployments, timeouts, database locks. Billing platforms retry with exponential backoff (typical: 1m, 5m, 30m, 2h over 24-72 hours).

Handler requirements:

  • Return 2xx quickly after durable enqueue, not after full fulfillment completes
  • Return 4xx only for malformed payloads you cannot fix (stops retries—use carefully)
  • Return 5xx for transient failures to trigger platform retries
  • Implement async processing via internal queue between HTTP handler and business logic

After max retries, events land in a dead letter queue (DLQ) on the platform side. Monitor DLQ depth; missed payment_confirmed events mean unfulfilled orders.

Ordering and Race Conditions

Events may arrive out of order: payment_detected after payment_confirmed due to network timing. Design state machines, not sequential assumptions.

Late payment_detected on already-paid invoice: no-op, log info. partially_paid followed by payment_confirmed: transition through partial or jump to paid based on cumulative amount.

Multi-Chain Event Payload Design

Crypto billing webhooks must be chain-explicit. Minimum fields:

  • network (e.g., solana-mainnet, base, ethereum)
  • token symbol and contract address (for ERC-20/SPL)
  • amount in token smallest units and human-readable decimal
  • tx_hash / signature
  • confirmations or finality_status
  • from_address (payer, when available)
  • to_address (invoice payment address)

Wrong-chain payments may emit invoice.payment_wrong_chain events—wire these to alerting and recovery workflows described in crypto-invoice-paid-wrong-chain.

Integration Architectures

Direct HTTP handler

Simplest: Express/FastAPI route verifies signature, updates DB. Suitable for low volume.

Queue intermediary

Webhook handler validates and publishes to SQS, RabbitMQ, or Redis streams. Workers process with retry and idempotency. Scales to high invoice volume.

iPaaS (Zapier, Make, n8n)

Non-technical teams connect webhooks to Slack, Google Sheets, email. Validate signature in a small Cloud Function first—do not skip verification.

Settlematic MCP

For AI-assisted workflows, compare dashboard clicks vs MCP tool calls in settlematic-mcp-vs-dashboard-workflows. MCP can poll invoice status; webhooks remain the production source of truth for event-driven systems.

Testing Webhooks Locally

Development workflow:

  • Use platform CLI or dashboard to send test events
  • Tunnel localhost via ngrok or Cloudflare Tunnel
  • Fixture recorded mainnet/testnet payment events
  • Chaos test: deliver same event twice, deliver out of order, deliver with invalid signature

Settlematic testnet invoices let you trigger real on-chain events without mainnet cost, validating end-to-end handler behavior.

Observability and Alerting

Production webhook systems need:

  • Structured logs with event_id, invoice_id, event_type, processing duration
  • Metrics: events received, processed, failed, duplicate skipped
  • Alerts: DLQ depth, 5xx rate spike, reconciliation mismatch count
  • Dashboards correlating webhook timestamp to on-chain block time

Slack or PagerDuty alerts on invoice.payment_wrong_chain and invoice.partially_paid prevent revenue leakage.

Compliance and Audit Logging

IRS and EU tax authorities expect substantiation of income. Webhook processing logs plus on-chain tx hashes form an audit chain. Store:

  • Raw webhook payload (redact PII per retention policy)
  • Signature verification result
  • Processing outcome and timestamp
  • Downstream actions triggered (fulfillment ID, GL entry ID)

Immutable log storage (S3 with object lock, append-only DB) strengthens audit posture.

Sample Webhook Payload Structure

Understanding payload shape accelerates handler implementation. A typical invoice.payment_confirmed event includes nested objects:

Your handler should validate event_type, extract data.invoice_id, and idempotently process on event_id. Never trust client-supplied amounts without signature verification over the full raw body—attackers craft plausible JSON without valid HMAC.

Rate Limiting and Backpressure

Webhook bursts occur when treasury batch-pays multiple invoices or a block includes clustered payments. Handlers without backpressure may OOM or timeout, causing platform retries that amplify load. Pattern: HTTP layer acknowledges in <200ms after writing to durable queue (SQS, Kafka, Redis Streams with AOF); worker pool consumes at sustainable rate. Configure max concurrent workers per organization for multi-tenant SaaS billing your platform on top of Settlematic. Circuit breakers pause downstream QuickBooks API calls when Intuit returns 429—queue events for retry rather than failing webhook acknowledgment.

Versioning and Schema Evolution

Billing platforms evolve payload schemas—new fields for fee_amount, payer_address, or bridge_metadata. Forward-compatible handlers ignore unknown fields (tolerant reader principle) while requiring known critical fields. Subscribe to changelog notifications; stage schema updates in sandbox before production deploy. Version header X-Webhook-Version: 2026-07 allows parallel handler code paths during migration windows.

Security Incident Response

If webhook secret leaks (committed to GitHub, exposed in log aggregation):

  • Rotate secret immediately in Settlematic dashboard
  • Deploy new secret to all workers
  • Review processed events for anomalous payment_confirmed during exposure window
  • Cross-check against on-chain truth; reverse fraudulent fulfillments
  • Post-mortem: secret scanning in CI, never log full payloads in production

Compromised webhook endpoints have caused fulfillment fraud in e-commerce—crypto's irreversibility makes prevention critical.

Load Testing Webhook Infrastructure

Before Black Friday or month-end invoice batches, simulate 10x normal payment_confirmed throughput against staging endpoint. Measure p99 latency, queue depth growth, and duplicate delivery handling. Tools: k6, Locust, or recorded production payloads replayed with modified event_id suffixes. Target: zero lost events, zero duplicate side effects, p99 acknowledgment under 500ms.

Correlation With Dashboard and MCP

When debugging missed fulfillment, correlate three timestamps: webhook created_at, on-chain block time, and dashboard paid status update. Skew between them diagnoses indexer lag vs handler failure vs MCP poll stale cache. Production systems treat webhook as source of truth; dashboard and Settlematic MCP queries are debugging conveniences only.

Webhook vs Polling: Cost Analysis

Polling Settlematic API every 30 seconds for 1,000 open invoices generates 2,880,000 requests per day—expensive and slow. Webhooks push only on state change: perhaps 50 events daily for same invoice volume. Infrastructure cost difference is orders of magnitude. Polling also misses sub-minute payment windows critical for time-sensitive fulfillment (concert tickets, domain transfers, API key provisioning). Reserve polling for disaster recovery when webhook endpoint is down and DLQ is empty—batch GET /invoices?status=open once per hour as safety net, not primary architecture.

Multi-Region Deployment Considerations

Global merchants should deploy webhook receivers in multiple regions with geo-DNS routing. Settlematic webhooks originate from defined IP ranges—allowlist in firewall rules. EU data residency: webhook payloads contain client PII (names, emails); process and store in EU region if GDPR data processing agreement requires. Sign DPA with Settlematic covering webhook payload contents. Retention policy: delete raw payloads after 90 days post-reconciliation, retain tx hash and invoice_id indefinitely for tax records per IRS expectations.

Webhook delivery guarantees are best-effort with exponential backoff—not exactly-once delivery. Your idempotent handler design is what makes the system exactly-once in effect. Document this distinction for auditors reviewing payment-triggered fulfillment controls.

Webhook handler code structure: reference architecture

Production webhook handlers benefit from layered architecture separating HTTP concerns from business logic:

Event router dispatches by event_type to focused handlers (handlePaymentConfirmed, handlePartiallyPaid, handleWrongChain). Each handler runs in database transaction with row-level lock on invoice record. Avoid monolithic switch statements without transactions — partial handler failure leaves inconsistent state. Language choice matters less than transactional discipline; Node.js, Python, Go, and Ruby all support this pattern.

Store raw payload before processing (redacted PII if required) so replay debugging does not depend on platform resending events. Payload storage retention aligns with tax record policy — tx hash and invoice_id permanent, raw email fields may rotate per GDPR.

Contract testing webhook integrations

Treat webhook payloads as API contracts. Record golden fixtures from sandbox payment_confirmed events; run contract tests in CI on every deploy verifying handler accepts current schema. When Settlematic adds optional fields, tests should pass without modification (tolerant reader). When critical fields rename, tests fail before production deploy.

Contract testing catches the common failure mode: developer updates handler for new feature, accidentally breaks signature verification by parsing JSON before HMAC check (JSON re-serialization changes byte order). Always verify HMAC on raw request body bytes, never on re-stringified parsed object.

Webhook-driven fulfillment vs manual approval gates

High-value B2B invoices may require human approval before fulfillment despite payment_confirmed webhook. Pattern: webhook enqueues fulfillment job in pending_approval state; Slack notification to account manager; approval button triggers actual provisioning. Do not block webhook acknowledgment on approval — acknowledge immediately, process approval async. Blocking acknowledgment causes platform retries and duplicate approval requests.

Document approval thresholds in integration spec: auto-fulfill under $5,000, manual approval above. Thresholds should match contract and fraud tolerance, not arbitrary engineering preference.

Webhook payload versioning and backward-compatible evolution

Billing platforms evolve webhook schemas as new chains, assets, and compliance fields emerge. Production handlers should parse payloads using tolerant reader pattern — required fields drive fulfillment logic; unknown fields log at debug level and ignore. Breaking changes — renaming transaction_hash to tx_id — should arrive with versioned endpoint path or schema_version field in payload; subscribe to platform changelog and pin integration tests to documented schema.

When platform announces new optional fields like payer_wallet or travel_rule_data, evaluate whether your compliance workflow needs them before engineering sprint. Premature parsing of undocumented fields creates fragility; delayed adoption of documented compliance fields creates regulatory gap. Maintain fixture library versioned alongside handler code — tag fixtures with platform API version captured from sandbox. Quarterly diff sandbox payload against production sample to detect silent schema drift before it breaks fulfillment during Black Friday volume.

Incident response when webhook endpoint is compromised

If webhook signing secret leaks or attacker gains ability to POST fake events to your endpoint, assume fulfillment integrity compromised until proven otherwise. Immediate steps: rotate webhook secret in dashboard, deploy new secret to handler, review fulfillment logs for anomalous activations without matching on-chain payments, cross-reference recent fulfillments against block explorers, notify security team and potentially affected customers if fraudulent access granted.

Post-incident hardening: restrict webhook endpoint to platform IP allowlist if supported, add secondary verification step comparing webhook amount to internal order record before high-value fulfillment, enable alerting on fulfillment rate exceeding historical baseline. Compromised webhook endpoint is not full treasury compromise in non-custodial architecture — attacker cannot drain wallets via webhook alone — but fraudulent digital goods fulfillment and ERP mis-posting cause real losses. Run tabletop exercise annually simulating leaked secret scenario; measure time to secret rotation and fulfillment audit completion.

EventWhen firedTypical action
invoice.sentEmail / link deliveredCRM activity log
payment.detectedTx seen on-chainOps alert (optional)
payment.confirmedConfirmations metRevenue recognition
invoice.paidBalance due zeroClose AR, stop dunning
Core webhook events

Sample payload fields

  • event_id - use for idempotency keys
  • invoice_id, client_id, fiat_amount_due, balance_remaining
  • payment.asset, payment.network, payment.tx_hash, payment.confirmed_at
  • org_id - tenant isolation for multi-workspace middleware

Frequently asked questions

How fast should my webhook handler respond?
Under 5 seconds ideally under 1 second. Acknowledge after durable write to queue or DB, process async.
What if my server is down during payment?
Platform retries for hours to days. Catch up when online; reconcile against platform API for missed events.
Should I trust webhook amount or re-query chain?
Trust signed webhook for real-time actions; independently verify at reconciliation. Platform dual-source verification reduces but does not eliminate your reconcile responsibility.
Can one webhook endpoint serve multiple organizations?
Yes, route by organization_id in payload. Use per-org secrets or include org in signature payload.
How do webhooks interact with QuickBooks?
Webhook handler enqueues accounting job; worker posts payment via QuickBooks API. See export-crypto-invoice-data-quickbooks-xero.
Does Settlematic support webhook signature verification?
Yes. Configure endpoints in dashboard; documentation covers signature algorithm and event schemas. Explore Settlematic Collect and pricing, or book a demo for enterprise webhook volume.

Continue reading

Start invoicing and accepting crypto payments

Collect and Gateway on one non-custodial platform - funds always sweep to wallets you control.