Skip to content
SwapWalletDocs
فارسیGet an API key

Accept crypto payments

Build a crypto checkout with the Payments API: create an invoice with its own deposit address, show it to the customer, and fulfill the order when the webhook says it’s paid.

This guide builds a crypto checkout: your customer picks a product, you create an invoice, they send crypto to the address it gives you, and SwapWallet tells your server the moment it arrives. The money lands in your business balance and, by default, moves straight on to your own SwapWallet account.

Before you start

  • A business on business.swapwallet.app. Sign in with your phone number or Telegram and create one.
  • Its business key (business-…), from your shop’s Settings › API key. Send it on every request as Authorization: Bearer business-…. Each shop has its own key, and it sees only that shop.
  • Invoices turned on for the business. SwapWallet enables API invoices per business, for verified businesses. Until then, creating one returns API_DISABLED; ask support to turn them on.
  • Optional: a default webhook URL in the shop’s settings, used by every invoice that doesn’t set its own.

The payment flow

  1. Create an invoice at checkout

    Price it in whatever you sell in (Toman, dollars or a token) and choose the token and network the customer pays with. SwapWallet converts the price at the current rate and gives the invoice its own deposit address.

    POST/v1/merchants/invoices/temporary-wallet
    curl -X POST https://swapwallet.app/api/v1/merchants/invoices/temporary-wallet \
      -H "Authorization: Bearer $SWAPWALLET_BUSINESS_KEY" \
      -H "Content-Type: application/json" \
      -d '{
      "amount": {
        "number": "2500000",
        "unit": "IRT"
      },
      "allowedToken": "USDT",
      "network": "BSC",
      "ttl": 3600,
      "orderId": "ORD-1042",
      "description": "Spotify Premium, 1 month",
      "webhookUrl": "https://pixelshop.example/webhooks/swapwallet",
      "returnUrl": "https://pixelshop.example/orders/1042"
    }'
    • orderId is your own order ID and must be unique per business: a second invoice with the same one is refused. Use it to find the invoice again after a timeout instead of creating another.
    • ttl (300 to 86,400 seconds) is how long the customer has to pay.
    • webhookUrl is where SwapWallet reports payments for this invoice.
  2. Show the customer where to pay

    The response has everything your payment page needs: the address, the exact amount in the chosen token, and links that open a wallet app with both filled in.

    JSON
    {
      "status": "OK",
      "result": {
        "id": "bcbb332e-0bf8-4da2-a42f-a75a0be6c36f",
        "walletAddress": "0xD54960E24Ff910731C04798937a60551879e8726",
        "amount": {
          "amount": { "number": "9.18", "unit": "USDT" },
          "usdValue": { "number": "9.18", "unit": "USD" },
          "userCurrencyValue": { "number": "2500632", "unit": "IRT" }
        },
        "links": [
          { "name": "SWAP_WALLET", "url": "https://t.me/swapwalletbot/app?startapp=app-invoice-bcbb332e-…", … },
          { "name": "TRUST_WALLET", "url": "https://link.trustwallet.com/send?…&amount=9.18", … }
        ],
        "expiredAt": "2026-11-23T10:12:04.318227Z",
        "createdAt": "2026-11-23T09:12:04.318512Z"
      }
    }

    Show walletAddress (with a QR code), amount.amount exactly as given, the network, and a countdown to expiredAt. Put the links under it as buttons: customers on a phone pay with one tap from SwapWallet or Trust Wallet.

    Tell the customer the network as plainly as the address. USDT sent on another network than the one you chose doesn’t reach the invoice.

  3. Get told when it’s paid

    When a transfer to the address is confirmed on the blockchain, SwapWallet sends a webhook to your webhookUrl with the invoice in it. Receive webhooks shows how to check that it really came from SwapWallet. Without a webhook endpoint, you can poll Retrieve an invoice instead.

  4. Fulfill the order once

    Deliver only when the invoice’s status is PAID or SETTLED, and only once per order: the same payment can be reported more than once.

    Node.js
    async function onPaidWebhook(invoice) {
      // Ask SwapWallet, don't trust the request body alone (or verify its hmac).
      const res = await fetch(
        `https://swapwallet.app/api/v1/merchants/invoices/${invoice.id}`,
        { headers: { Authorization: `Bearer ${process.env.SWAPWALLET_BUSINESS_KEY}` } },
      );
      const { result } = await res.json();
    
      const order = await db.orders.findByInvoiceId(result.id);
      if (!order || order.status === 'fulfilled') return;      // unknown or done already
      if (result.status !== 'PAID' && result.status !== 'SETTLED') return; // not covered yet
    
      await db.orders.markFulfilled(order.id, result.paidAmount);
      await deliver(order);
    }

Invoice statuses

StatusMeaningDeliver?
ACTIVEWaiting for payment, or paid only in part so far.No
PAIDThe full amount has arrived.Yes
SETTLEDPaid, and the money has already moved to your SwapWallet account.Yes
EXPIREDexpiredAt passed before the full amount arrived.No

Short, extra and late payments

Customers don’t always send exactly what was asked. Nothing is refunded or rejected automatically; every confirmed transfer to the address is credited to the invoice as it arrives.

  • Too little. paidAmount grows with each transfer and the invoice stays ACTIVE until the total reaches amount. The customer can send the rest to the same address before it expires.
  • Too much. The invoice becomes PAID and the whole amount is credited; extraStatus reads OVER_PAID. Settle any difference with the customer yourself.
  • Late. Transfers that arrive up to 12 hours after expiredAt still count, so an EXPIRED invoice can turn PAID. Keep listening for webhooks during that window, and stop showing the address once the invoice expires: after 12 hours it can be given to another invoice.

Where the money goes

Each payment is credited to your business balance minus SwapWallet’s fee, which your business pays on these invoices. By default it then moves straight to the shop owner’s SwapWallet account, where the invoice shows as SETTLED and you can swap, hold or withdraw it like any other balance. Check the balance and transactions of your business any time.

Selling for a fixed Toman price and want the customer to pay in Toman? Use a Toman receipt instead of a crypto invoice.