🎉 75% of content is free forever — Unlock Premium from $10/mo →
CW
NEWSLIVESearch All Content
đŸ’ŧ Servicesâ„šī¸ Aboutâœ‰ī¸ ContactView Pricing Plansfrom $10

Crypto Payment Gateway Architecture

Blockchain Payment SystemsđŸŸĸ Free Lesson

Introduction to Payment Gateways

A crypto payment gateway is a service that enables merchants to accept cryptocurrency payments and optionally convert them to fiat currency. It handles invoice generation, payment detection, confirmation monitoring, and settlement.

Gateway vs. Processor

AspectPayment GatewayPayment Processor
Primary RoleConnects merchant to blockchainHandles actual payment flow
Invoice CreationYesNo
Payment DetectionVia blockchain monitoringVia gateway notification
SettlementConverts and transfers fundsManages fund flow
ExamplesBTCPay Server, NOWPaymentsBitPay, Coinbase Commerce

Gateway Architecture

Crypto Payment Gateway ArchitectureMerchant LayerE-Commerce PlatformPOS TerminalMobile AppGateway CoreAPI ServerREST/GraphQL endpointsWebhook EngineEvent notification systemInvoice ManagerCreate, track, expireExchange RateReal-time pricing feedBlockchain MonitorMempool & block scannerSettlement EngineBatch or instant payoutDatabasePostgreSQL / RedisSecurity LayerAuth, rate limiting, WAFBlockchain LayerBitcoin NetworkEthereum / EVMLightning NetworkSolana / PolygonStellar / RippleFiat Off-RampBank / Payment RailACH / SEPA / SWIFT

Merchant API Design

Core API Endpoints

Architecture Diagram
POST /api/v1/invoices          Create new payment invoice
GET  /api/v1/invoices/:id      Get invoice status
GET  /api/v1/invoices          List all invoices
POST /api/v1/refunds           Process refund
GET  /api/v1/rates             Get exchange rates
GET  /api/v1/wallets           Get merchant wallets
POST /api/v1/webhooks          Register webhook endpoint
GET  /api/v1/transactions      List transactions

Invoice Creation Request

{
  "amount": "50.00",
  "currency": "USD",
  "accepted_currencies": ["BTC", "ETH", "USDC"],
  "title": "Order #12345",
  "description": "Product purchase",
  "callback_url": "https://merchant.com/webhook",
  "redirect_url": "https://merchant.com/success",
  "expires_in": 900,
  "metadata": {
    "order_id": "12345",
    "customer_id": "cust_abc"
  }
}

Invoice Response

{
  "id": "inv_x9k2m4p6",
  "status": "pending",
  "amount": "50.00",
  "currency": "USD",
  "addresses": {
    "BTC": "bc1qxy2kgdygjrsqtzq2n0yrf2493p83kkfjhx0wlh",
    "ETH": "0x742d35Cc6634C0532925a3b844Bc9e7595f2bD3e",
    "USDC": "0x742d35Cc6634C0532925a3b844Bc9e7595f2bD3e"
  },
  "amounts": {
    "BTC": "0.001234",
    "ETH": "0.020521",
    "USDC": "50.00"
  },
  "qr_codes": {
    "BTC": "data:image/png;base64,...",
    "ETH": "data:image/png;base64,..."
  },
  "expires_at": "2024-01-15T12:15:00Z",
  "created_at": "2024-01-15T12:00:00Z"
}

Webhook System

Webhooks notify merchants of payment status changes in real-time:

Webhook Event FlowBlockchain EventTX confirmedGateway MonitorDetects paymentEvent QueueKafka / RabbitMQWebhook DispatcherRetry + signatureMerchant EndpointPOST /webhookSigned payload with HMAC-SHA256

Webhook Payload Structure

{
  "event": "invoice.confirmed",
  "timestamp": "2024-01-15T12:05:30Z",
  "invoice_id": "inv_x9k2m4p6",
  "data": {
    "status": "confirmed",
    "amount_received": "0.001234",
    "currency": "BTC",
    "txid": "a1b2c3d4e5f6...",
    "confirmations": 3,
    "amount_usd": "50.00"
  },
  "signature": "hmac-sha256:abc123..."
}

Webhook Events

EventTriggerData
invoice.createdInvoice generatedInvoice details
invoice.paidPayment detected (0-conf)TXID, amount
invoice.confirmedRequired confirmations reachedFinal amount
invoice.expiredTimeout exceededFinal status
invoice.refundedRefund processedRefund details
payout.completedSettlement sentPayout TXID

Webhook Security

Architecture Diagram
Verification Process:
  1. Extract signature from X-Webhook-Signature header
  2. Compute HMAC-SHA256 of request body using API secret
  3. Compare computed signature with received signature
  4. Reject if signatures don't match
  5. Reject if timestamp exceeds 5-minute window (replay protection)

Multi-Coin Support

Supported Blockchain Networks

NetworkNative TokenConfirmation TimeAvg Fee
BitcoinBTC10–60 min5.00
Bitcoin (Lightning)BTC<1 second< $0.01
EthereumETH12–15 sec50.00
PolygonMATIC2 seconds< $0.01
SolanaSOL400 ms< $0.01
USDC (Ethereum)USDC12–15 sec50.00
USDC (Solana)USDC400 ms< $0.01
StellarXLM3–5 sec< $0.001

Address Derivation

HD (Hierarchical Deterministic) wallet derivation for each coin:

Architecture Diagram
BIP-44 Path Structure:
  m / purpose' / coin_type' / account' / change / address_index

Examples:
  BTC:  m/84'/0'/0'/0/0    (Native SegWit)
  ETH:  m/44'/60'/0'/0/0   (Ethereum)
  SOL:  m/44'/501'/0'/0'   (Solana)

Fiat On-Ramp Integration

Fiat On-Ramp OptionsBank TransferACH / SEPAFee: 0.5-1%1-3 business daysCard PaymentVisa / MastercardFee: 2-3%InstantApple PayNFC / In-AppFee: 2.5-3%InstantWire TransferSWIFT / FedwireFee: $15-501-2 business daysOn-Ramp ComparisonSpeed: Card > Wire > ACHCost: ACH < Wire < CardLimits: Wire > ACH > Card

Checkout Flow Integration

Hosted Checkout (Redirect)

Architecture Diagram
Flow:
  1. Customer clicks "Pay with Crypto"
  2. Redirect to gateway hosted page
  3. Select currency and complete payment
  4. Redirect back to merchant success page
  5. Webhook confirms payment to merchant

Inline Checkout (iframe)

Architecture Diagram
Flow:
  1. Customer clicks "Pay with Crypto"
  2. iframe opens with payment UI
  3. Customer completes payment in iframe
  4. iframe closes, parent page receives event
  5. Webhook confirms payment to merchant

Direct API Integration

Architecture Diagram
Flow:
  1. Customer clicks "Pay with Crypto"
  2. Merchant calls API to create invoice
  3. Display QR code / payment URI
  4. Customer pays from wallet
  5. Poll API or receive webhook
  6. Update order status

Settlement Options

Settlement TypeTimingFeeBest For
Instant FiatT+01–2%Risk-averse merchants
Daily BatchT+10.5–1%Medium volume
Weekly BatchT+70.25–0.5%High volume
Hold CryptoNone0%Crypto-forward businesses
Hybrid (50/50)T+10.5–1%Balanced approach

Real-World Examples

BTCPay Server

Open-source, self-hosted payment processor. No fees, full control, supports Lightning Network and on-chain Bitcoin. Used by over 10,000 merchants including major open-source projects.

CoinGate

Lithuanian-based gateway supporting 70+ cryptocurrencies. Offers instant fiat conversion, batch settlements, and a merchant dashboard. Processing $50M+ monthly across 5,000+ merchants.

NOWPayments

Non-custodial payment gateway with 150+ supported cryptocurrencies. Features include point-of-sale apps, recurring payments, and API-first design. No KYC required for merchants.

Trade-Offs

AdvantageDisadvantage
Lower fees than cardsPrice volatility during settlement
Global reachRegulatory complexity per jurisdiction
No chargebacksCustomer support for crypto issues
Faster settlementsIntegration complexity
Access to crypto-native customersTax reporting requirements

Interview Questions

  1. Describe the complete architecture of a crypto payment gateway, including all major components and their interactions.

    A crypto payment gateway consists of: (1) API Server handling merchant requests; (2) Invoice Manager creating and tracking payment requests; (3) Exchange Rate Service providing real-time pricing; (4) Blockchain Monitor scanning for incoming transactions; (5) Webhook Engine notifying merchants of status changes; (6) Settlement Engine handling payouts; (7) Database storing invoice and transaction data; (8) Security Layer managing authentication and rate limiting. The flow starts with the merchant creating an invoice via API, the gateway generating addresses and amounts, monitoring blockchain for payment, confirming via webhooks, and settling to the merchant's account.

  2. How does a payment gateway handle the risk of double-spend attacks on zero-confirmation transactions?

    Gateways employ several mitigation strategies: (1) RBF (Replace-By-Fee) detection — monitoring for conflicting transactions; (2) Chain analysis — checking the fee level and mempool position; (3) Lightning Network — for instant, secure payments; (4) Confirmation waiting — requiring 1-3 confirmations for higher-value transactions; (5) Merchant risk scoring — varying confirmation requirements based on transaction history. Most gateways require at least 1 confirmation for Bitcoin but may accept 0-conf for small amounts with Lightning.

  3. Explain the webhook retry mechanism and why idempotency is critical for payment gateways.

    Webhooks are retried with exponential backoff (e.g., 1min, 5min, 30min, 2hr, 24hr) because merchants' endpoints may be temporarily unavailable. Idempotency ensures duplicate webhooks don't cause duplicate processing (e.g., double-fulfilling an order). Each webhook includes a unique event ID and signature. Merchants must store processed event IDs and reject duplicates. The gateway must also ensure exactly-once delivery semantics despite at-least-once webhook delivery, which requires careful database design with unique constraints.

Quiz Questions

  1. What is the primary purpose of HMAC-SHA256 signatures on webhook payloads?

    • a) To compress the payload data
    • b) To verify the payload hasn't been tampered with and came from the gateway
    • c) To encrypt the payment data
    • d) To speed up webhook delivery
  2. Which settlement option provides the lowest risk for merchants who want to avoid cryptocurrency volatility?

    • a) Holding Bitcoin for 90 days
    • b) Converting to stablecoins weekly
    • c) Instant fiat conversion at payment confirmation
    • d) Receiving payments only in USDC
  3. In the BIP-44 key derivation path m/84'/0'/0'/0/0, what does the purpose 84' indicate?

    • a) Ethereum address format
    • b) Native SegWit Bitcoin address format
    • c) Lightning Network address format
    • d) Legacy Bitcoin address format
CW

ChatWhole Learn Editorial Team

Written by experienced data scientists, software engineers, and educators. All content is reviewed by industry professionals to ensure accuracy and relevance.

Last reviewed: 2026-09-22

—
☆☆☆☆☆
0 ratings

Rate & Feedback

Need Expert Blockchain Help?

Get personalized tutoring, project support, or professional consulting.

Advertisement