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 asAuthorization: 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
Create an invoice at checkout
POSTPrice 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.
/v1/merchants/invoices/temporary-walletcurl -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" }'const response = await fetch('https://swapwallet.app/api/v1/merchants/invoices/temporary-wallet', { method: 'POST', headers: { Authorization: `Bearer ${process.env.SWAPWALLET_BUSINESS_KEY}`, 'Content-Type': 'application/json', }, body: JSON.stringify({ 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', }), }); const data = await response.json(); console.log(data.result);import os import requests response = requests.post( "https://swapwallet.app/api/v1/merchants/invoices/temporary-wallet", headers={"Authorization": f"Bearer {os.environ['SWAPWALLET_BUSINESS_KEY']}"}, json={ "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", }, ) print(response.json()["result"])<?php $ch = curl_init('https://swapwallet.app/api/v1/merchants/invoices/temporary-wallet'); curl_setopt_array($ch, [ CURLOPT_RETURNTRANSFER => true, CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_HTTPHEADER => [ 'Authorization: Bearer ' . getenv('SWAPWALLET_BUSINESS_KEY'), 'Content-Type: application/json', ], CURLOPT_POSTFIELDS => json_encode([ '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', ]), ]); $data = json_decode(curl_exec($ch), true); print_r($data['result']);package main import ( "fmt" "io" "net/http" "os" "strings" ) func main() { body := strings.NewReader(`{ "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" }`) req, _ := http.NewRequest("POST", "https://swapwallet.app/api/v1/merchants/invoices/temporary-wallet", body) req.Header.Set("Authorization", "Bearer "+os.Getenv("SWAPWALLET_BUSINESS_KEY")) req.Header.Set("Content-Type", "application/json") res, err := http.DefaultClient.Do(req) if err != nil { panic(err) } defer res.Body.Close() data, _ := io.ReadAll(res.Body) fmt.Println(string(data)) }orderIdis 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.webhookUrlis where SwapWallet reports payments for this invoice.
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.
{ "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.amountexactly as given, the network, and a countdown toexpiredAt. Put thelinksunder 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.
Get told when it’s paid
When a transfer to the address is confirmed on the blockchain, SwapWallet sends a webhook to your
webhookUrlwith 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.Fulfill the order once
Deliver only when the invoice’s
statusisPAIDorSETTLED, and only once per order: the same payment can be reported more than once.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
| Status | Meaning | Deliver? |
|---|---|---|
ACTIVE | Waiting for payment, or paid only in part so far. | No |
PAID | The full amount has arrived. | Yes |
SETTLED | Paid, and the money has already moved to your SwapWallet account. | Yes |
EXPIRED | expiredAt 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.
paidAmountgrows with each transfer and the invoice staysACTIVEuntil the total reachesamount. The customer can send the rest to the same address before it expires. - Too much. The invoice becomes
PAIDand the whole amount is credited;extraStatusreadsOVER_PAID. Settle any difference with the customer yourself. - Late. Transfers that arrive up to 12 hours after
expiredAtstill count, so anEXPIREDinvoice can turnPAID. 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.