Skip to content
Private beta · Not open to the public yet. Accounts are by invitation only. Request access →
AywaPay
All articles

Developer guide

How to integrate a crypto payment API, step by step

Create crypto invoices from your server, send customers to the payment page and mark orders paid from signed webhooks. With cURL and Node.js examples.

· 8 min read

A crypto payment API lets your own checkout take Bitcoin, USDT and other coins without you running wallets or watching blockchains. Your server asks the gateway for an invoice, the customer pays on the gateway's payment page, and the gateway tells your server when the money has arrived.

This guide walks through a complete integration with the AywaPay API v2: keys, creating an invoice, the payment page, webhooks, test mode and the cases that trip people up. The same flow applies to most gateways, so it is useful even if you are still comparing providers.

How a crypto payment integration works

  1. Your server creates an invoice with the order number, the price and, if you like, the coins you accept.
  2. The API answers with a `payment_url`. You redirect the customer there (or open it in a new tab).
  3. The customer pays from any wallet or exchange. The page shows the exact amount, the address and a QR code, and updates live.
  4. The gateway sends a webhook to your server at each step: part paid, confirming, paid, overpaid, underpaid or cancelled.
  5. Your server marks the order paid when the webhook says so, after checking its signature.

The browser never talks to the API. The API key stays on your server; the customer only ever sees the payment page.

Step 1: get an API key

In the dashboard, open your store and its API tab, then create the store's API key. Two habits keep it safe:

  • Send it only in the Authorization: Bearer header. A key in the URL is refused (key_in_url), so it can't leak into logs or browser history.
  • Turn on Allowed IPs for the store so the key only works from your servers.

Every store also has a test key that starts with test_. It works with the same endpoints but moves no money, which is what you want while building.

Step 2: create an invoice

Price the order in a fiat currency and let the customer choose a coin, or price it directly in one coin. order_id is your own order number and must be unique per store, so a retried request can't create a second invoice for the same order.

cURL
curl -X POST "https://api.aywapay.com/api/v2/invoices" \
  -H "Authorization: Bearer $AYWAPAY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "order_id": "1042",
    "description": "Pro plan",
    "price_amount": "49.99",
    "price_currency": "USD",
    "coins": ["USDT-BEP20", "USDT-TRC20"],
    "callback_url": "https://shop.example/webhooks/aywapay",
    "success_url": "https://shop.example/thanks",
    "cancel_url": "https://shop.example/cart"
  }'

The answer is the invoice itself: its id, status (pending at first), amount, amount_received, amount_remaining, expires_at and the payment_url. Save the invoice id next to your order.

Step 3: send the customer to the payment page

Redirect to payment_url. The page handles everything a customer needs: choosing a coin and network, the exact amount, a QR code, a countdown and live status. When the payment is done the customer can go back to your success_url.

Never mark an order paid because the customer landed on your success page. Only the webhook (or reading the invoice from the API) tells you money really arrived.

Step 4: handle webhooks

Each change to an invoice is sent to your callback_url as a JSON POST. The event type tells you what happened, and data carries the full invoice.

EventWhat to do
invoice.partially_paidSome money arrived and is already credited. Wait for the rest.
invoice.confirmingThe full amount is on the blockchain. Show “payment received, confirming”.
invoice.paidPaid in full and confirmed. Fulfil the order.
invoice.overpaidPaid more than asked; all of it is credited. Fulfil the order.
invoice.underpaidTime ran out with part of the money. Decide: ask for the rest, fulfil, or refund.
invoice.cancelledClosed with nothing received.

Every webhook is signed. Check the signature before you trust the body: how to verify crypto payment webhooks explains it with code. Answer with any 2xx status; anything else is retried, and the same event can arrive twice, so process each event id once.

Step 5: test without real money

Create invoices with your test key. Test invoices have no deposit address and put nothing on a blockchain. Their payment page has Simulate buttons (paid, overpaid, underpaid, expire), and each one sends your normal webhook with "test": true. Run through every button before you go live.

Cases worth handling from day one

  • Underpayments. Customers sometimes send a little less, often because an exchange took its withdrawal fee from the amount. The webhook carries amount_received and amount_remaining, so you can credit exactly what arrived. Read what happens when a customer underpays or overpays.
  • Late payments. A payment that arrives after the invoice expired is still credited, and you get a webhook for it.
  • Duplicate orders. Reusing an order_id returns duplicate_order. Look the invoice up with GET /api/v2/invoices?order_id=1042 instead of creating a new one.
  • Retries. Make your webhook handler idempotent: the same event id must not fulfil an order twice.

Don't want to write code?

If your shop runs on WooCommerce, WHMCS, PrestaShop or OpenCart, a ready-made plugin does all of the above with just your API key and webhook secret. See integrations. For one-off sales, a payment link needs no integration at all.

Frequently asked questions

Do I need a crypto wallet to use a crypto payment API?
No. Payments land in your gateway balance, and you withdraw to your own wallet whenever you like. You never manage addresses or private keys for each payment.
How long does an integration take?
A basic flow (create an invoice, redirect, handle the paid webhook) usually takes a developer a few hours. Testing every webhook case with the Simulate buttons is worth an extra hour.
Can I choose which coins customers see?
Yes. Pass a coins list when you create the invoice, or leave it out to offer every coin the store accepts.

Keep reading

Get started

Start accepting crypto today

  1. 01Request access
  2. 02Get your invite by email
  3. 03Add your store and get paid