Blog

Crypto payments API quickstart: get paid with one call

CoinStackUpdated 11 min read
Integrations

To accept a crypto payment through the CoinStack API, send one POST /checkouts request from your server with an amount and a currency. The response contains a checkout_id, which you save with the order, and a url, which you redirect the customer to. The customer pays on that hosted page with the token and network they choose, and a signed checkout.completed webhook tells your server when to fulfill. The smallest checkout is worth $1.

What do you need before the first request?

Two secrets and an HTTPS endpoint. Create an account with Instant sign-up, then:

  1. Open Developers in the dashboard, select New API key, and set Access to Read and write. The key starts with sk_ and is shown once.
  2. On the same page, select Add webhook and enter an https:// URL on your server. The URL must use a domain name, not an IP address. Copy the signing secret, which starts with whsec_ and is also shown once.

Put both in environment variables (COINSTACK_API_KEY and COINSTACK_WEBHOOK_SECRET below). The key goes in an Authorization: Bearer header from your server only. A key in a web page or a mobile app can be read by anyone, and anyone holding it can create checkouts on your account. A read-only key can list and get checkouts but gets 403 Invalid permissions on create, so a key that fails here with a 403 has the wrong access level.

How do you create a checkout with cURL?

Every endpoint lives under https://coinstack.net/api/v1. Request bodies are JSON and need the Content-Type: application/json header. Only amount and currency are required; the rest of this example is what a real order usually sends.

curl https://coinstack.net/api/v1/checkouts \
  -H "Authorization: Bearer $COINSTACK_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "amount": "25.00",
    "currency": "USD",
    "email": "[email protected]",
    "reference": "order-1042",
    "description": "Order #1042",
    "success_url": "https://example.com/orders/1042/thanks",
    "cancel_url": "https://example.com/cart",
    "metadata": { "order_id": "1042" }
  }'

amount is a string, never a JSON number, and it may not have more decimal places than the currency has: "25.00" for USD, "2500" for JPY. currency is any of the 146 supported currency codes. Each field's limits are in the Create a checkout reference.

The same request in Node.js

This is the docs' own example, using the fetch built into Node.js 18 and later. It checks success before it touches the result, because every response from the API is wrapped the same way.

const response = await fetch("https://coinstack.net/api/v1/checkouts", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.COINSTACK_API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    amount: "25.00",
    currency: "USD",
    reference: "order-1042",
    success_url: "https://example.com/orders/1042/thanks",
    cancel_url: "https://example.com/cart",
  }),
});

const body = await response.json();

if (!body.success) {
  throw new Error(body.response);
}

console.log(body.response.checkout.url);

A success is HTTP 200 with {"success": true, "response": {...}}. A failure is a 4xx or 5xx with {"success": false, "response": "Invalid amount"}, where the message names the rejected field. The errors page asks you to branch on the status code and success, not on the message text, which is written for people. A 400, 401, 403 or 404 will fail the same way if you resend it; a 500 or a timeout is worth one retry, handled as described further down.

Which fields in the response matter?

The checkout comes back under response.checkout. A fresh one for the request above looks like this, trimmed to the fields you will use:

{
  "checkout_id": "8f3b2c1e-5d47-4a9b-b6e0-2c7f1a9d4e53",
  "status": "pending",
  "amount": "25.00000000",
  "value": "25.00000000",
  "fee": "0.20000000",
  "received": "0",
  "expires_at": "2026-12-03T16:20:11.482501Z",
  "url": "https://coinstack.net/checkout/8f3b2c1e-5d47-4a9b-b6e0-2c7f1a9d4e53"
}
FieldWhat it tells youWhat to do with it
checkout_idThe checkout's ID, a UUIDStore it on the order. Webhooks are matched by it
urlThe hosted checkout pageRedirect the customer here
statuspending until something is paidFulfill only on completed (or resolved)
amountWhat you charged, in your currencyCompare with your order total if you like
valueThe same amount in US dollars, fixed at creationUse it for reporting in USD
feeThe 0.8% fee for the full amount, in USDOn $25 that is $0.20
receivedUSDC that has reached your wallet so farRecord it for your books; never use it to decide "paid"
expires_atWhen the checkout closes if unpaidShow it, or decide what happens to the order after it
underpaid, overpaid, lateFlags that add detail to the statusHandle them once you are live

Two details trip people up. Amounts are strings with a varying number of decimals, so "25.00000000" and "25.00" are the same number: parse with a decimal type and do not compare the strings. And empty text fields come back as "" rather than being left out, while time fields with no value yet, such as completed_at, are null.

received is lower than value on a fully paid checkout, because the fee and the network cost come out before the USDC settles. In the fees and settlement guide example, a $25 checkout paid with USDC on Base settles 24.776432 USDC. That is why status is the field to act on.

Reference or metadata: which should you use?

Both are stored with the checkout and come back every time you read it, including inside webhook events. They do different jobs.

reference is one string of up to 200 characters, such as your order number. It is the one field you can search by later with GET /checkouts?reference=order-1042. References do not have to be unique, and a search returns every checkout that shares one. That is useful: an order the customer tried to pay twice shows both attempts.

metadata holds up to 50 key-value pairs. Keys can be up to 40 characters and values up to 500, and every value must be a string. {"order_id": 1042} fails with Invalid metadata; {"order_id": "1042"} works. Put the identifiers your webhook handler needs here (order ID, customer ID, plan name) so the handler can act without another lookup.

A sensible default is reference set to the order number a human would search for and metadata set to your internal IDs.

How do you retry a create request safely?

Creating a checkout twice makes two checkouts. If a create request times out, you do not know whether it went through, so look before you send it again:

curl "https://coinstack.net/api/v1/checkouts?reference=order-1042" \
  -H "Authorization: Bearer $COINSTACK_API_KEY"

If the list holds a pending checkout created moments ago, use it. If it is empty, create a new one. The errors page recommends this pattern, and it only works if every create request carries a reference. The Python tutorial covers the same API from Flask and Django.

Send the customer to the checkout page

Redirect the browser to url. A 303 See Other from your server is the cleanest choice after a form POST. On that page the customer picks a token and network, sees the address, the exact amount and a QR code, and pays from any wallet or straight from an exchange. There is no wallet to connect.

success_url and cancel_url are links on that page, not automatic redirects. The Return to merchant button linking to success_url appears once the checkout is completed; cancel_url is offered before payment and again if the checkout expires. The customer may close the tab and never click either one, which is why fulfillment must hang on the webhook. Put {CHECKOUT_ID} in either URL and it is replaced with the checkout's ID:

https://example.com/return?checkout={CHECKOUT_ID}

How long does a checkout stay open?

By default, 24 hours. Send expires_at in RFC 3339 format to set anything from 10 minutes to 365 days from now; outside that range the API answers Invalid expires_at. In Node.js, a 30-minute checkout is new Date(Date.now() + 30 * 60_000).toISOString().

Pick the expiry from your business, not from the network. A ticket or a limited-stock item you hold for the buyer suits 30 minutes. An invoice to a client suits 14 days. Expiry is separate from the price lock: once the customer picks a token, the amount is held with no time limit for stablecoins, 60 minutes for BTC and 20 minutes for other tokens. Price locks at checkout explains what happens after that window.

To close a checkout early, for example when the customer cancels the order on your site, call POST /checkouts/{checkout_id}/expire. Only a pending or partial checkout can be expired. A payment that arrives after expires_at is still recorded: if it covers the amount, the checkout becomes completed with late set to true, so decide now what your system does with a paid order it already canceled. Overpaid and late crypto payments covers the options.

Confirm the payment with a webhook

When the checkout is paid in full, CoinStack sends a POST to your webhook URL with a JSON body and a CoinStack-Signature header:

{
  "event_id": "e41b7c92-3a5d-4f8e-b1c6-9d2a7f4e0b85",
  "kind": "checkout.completed",
  "data": { "checkout": { "checkout_id": "8f3b2c1e-5d47-4a9b-b6e0-2c7f1a9d4e53", "status": "completed" } },
  "created_at": "2026-12-02T16:24:37.905218Z"
}

The real data.checkout carries every field of the checkout, including your reference and metadata. Your handler does four things in order. It verifies the signature on the raw body: the header is t=<unix seconds>,v1=<hex>, and v1 must equal the HMAC-SHA256 of t, a full stop and the body, keyed with the whole whsec_ secret, compared in constant time, with t no more than 5 minutes old. It skips an event_id it has already handled, because the same event can arrive twice. It checks that checkout_id belongs to an order you created. Then it marks the order paid and answers with any 2xx within 10 seconds.

A delivery that fails, times out or gets a redirect is retried after 1 minute, 5 minutes, 30 minutes, 2 hours, 5 hours, 8 hours and 8 hours: 8 attempts over about a day. The docs single out one cause of failed signature checks: a framework that parsed the JSON before the handler saw it. How to verify payment webhooks covers that pitfall framework by framework, and the Node.js and Express tutorial has a complete handler you can run.

If you would rather poll, GET /checkouts/{checkout_id} returns the checkout with its payments at any time. Polling works as a backstop, not as the main signal.

What should you store for each checkout?

Keep a small table next to your orders. Everything else can be fetched from the API when you need it.

StoreWhy
checkout_id and your order IDThe webhook only gives you the checkout; this row tells you which order to update
urlSend it again if the customer loses the tab, while the checkout is open
expires_atDecide when to create a fresh checkout instead of reusing the old one
Your last known statusShow the customer where their payment stands
Each handled event_idSkip duplicate deliveries
received at completionThe USDC that actually reached your wallet, for bookkeeping

The API key and the webhook secret belong in environment variables or a secrets manager, never in this table.

Try the whole flow before launch

Three checks cover it. The demo checkout shows the exact page your customers will get. Select Send test on your webhook in the dashboard: it sends a sample checkout.completed event for a $10 checkout with the reference test, which shows whether your server accepts and verifies a real signature. Your handler should answer 200 and change nothing, because that checkout ID matches none of your orders. Then create a real checkout for $1, pay it from a wallet, and watch the order flip to paid. How to test a crypto checkout has a fuller launch checklist.

Frequently asked questions

Do I need a library to call the API?

No. The API is plain HTTPS with JSON bodies and a Bearer header, so the HTTP client your language already has is enough. The docs show every call in cURL, Node.js, Python and PHP. If you prefer generated types, the OpenAPI 3.1 file describes every endpoint, field and error message and works with standard client generators.

Can I price the checkout in euros or another currency?

Yes. Send any of the 146 supported currency codes with an amount in that currency, using its normal number of decimals. The amount is converted to US dollars when the checkout is created and stored as value, which never changes afterwards. The customer still pays in the token they pick, and you receive USDC.

Can I create checkouts from the browser?

Not safely. Creating a checkout needs your API key, and a key sent to the browser can be copied and used to create checkouts on your account. Create the checkout on your server and send the browser only the url. If you want the customer to stay on your own page, the server can also fetch quotes and pass the address and amount to your front end.

How do I show the address and amount in my own interface instead of the hosted page?

Create the checkout as usual, then call POST /checkouts/{checkout_id}/quotes with the network and token the customer chose. Each quote returns an address, a remaining amount in the token's smallest unit and a uri for a QR code. Build your own crypto checkout walks through it.

What does the customer see if the checkout expires?

The checkout page offers your cancel_url again, if you set one, so the customer has a way back to your site. Your server gets a checkout.expired event, which every webhook receives unless you limited its list of events. If nothing was paid, create a new checkout when the customer wants to try again. A partly paid checkout that expires has underpaid set to true and needs a decision: resolve it or refund.

More posts