A complete technical walkthrough for integrating a crypto payment API. Covers invoice creation, address generation, webhook handling, signature verification, and error handling with code examples in Node.js and Python.
Integrating a crypto payment gateway is fundamentally simpler than integrating a card processor. There is no PCI compliance scope, no 3DS authentication flows, no redirect pages. The core loop is: create an invoice, display a payment address to the user, receive a webhook when the payment confirms. This guide walks through each step with production-ready code.
Architecture Overview
A crypto payment integration has four components: (1) your server calls the Bekena API to create an invoice, (2) you display the payment address and amount to the customer, (3) Bekena monitors the blockchain and calls your webhook when payment arrives, (4) your webhook handler verifies the signature and updates your order state.
Step 1: Create an Invoice
Step 2: Display the Payment Address
The invoice response contains a payment address and exact crypto amount. Display both clearly to the customer. Always show the amount in crypto (not just in USD) so the customer sends the exact amount. A QR code significantly improves mobile UX — most crypto wallets scan QR codes natively.
Step 3: Handle the Webhook
When payment confirms on-chain, Bekena sends a POST request to your webhookUrl. Always verify the signature before trusting the payload. Bekena signs each webhook with HMAC-SHA256 using your webhook secret, and the signature is in the X-Bekena-Signature header.
Step 4: Python Example
Idempotency: Handling Duplicate Webhooks
Webhooks can be delivered more than once. Network retries, server restarts, or timeout recoveries can cause the same event to arrive multiple times. Always make your webhook handler idempotent — check whether the invoiceId has already been processed before fulfilling the order.
Testing Your Integration
Use ngrok or Cloudflare Tunnel to expose your local webhook endpoint during development. Create a test invoice via the API, send a small real payment to the generated address, and verify your webhook handler receives and processes the confirmation correctly. For automated testing, use the Bekena sandbox environment with its test transaction simulator.
Production Checklist
- ✓Webhook signature verification implemented and tested
- ✓Idempotency check in webhook handler (prevent double-fulfillment)
- ✓Invoice expiry handled gracefully (show "payment expired" UI)
- ✓Crypto amount displayed clearly with network label (TRC20, ERC20, etc.)
- ✓QR code generated for payment address (improves mobile conversion)
- ✓Webhook endpoint returns 200 immediately (async processing)
- ✓Failed webhook retries: Bekena retries 3× with exponential backoff
- ✓Reconciliation: daily check of confirmed invoices vs your order DB