Skip to main content
A webhook is a URL on your server. When a checkout or payment changes, CoinStack sends a signed POST request to it, so your system learns about the change without asking.

Add a webhook

In the dashboard, open Developers, select Add webhook, and enter the URL. Or use the API:
The response includes the signing secret. It starts with whsec_ and is shown only once, so store it now.
  • The URL must start with https:// and use a domain name, not an IP address.
  • Leave events out to receive every event.
  • An account can have up to 10 webhooks.

Events

Most integrations only need checkout.completed. Add checkout.expired if you release stock or cancel orders when a checkout closes unpaid.

The request

Every event is a POST with a JSON body and a CoinStack-Signature header.
data holds the checkout or payment as it was when the event happened. The fields are the same as in the API reference.

Verify the signature

Anyone can send a request to your URL, so check that each one came from CoinStack before you act on it. The CoinStack-Signature header looks like this:
t is the time the request was signed, in Unix seconds. v1 is the signature. To check it:
  1. Read t and v1 from the header.
  2. Join t, a full stop and the raw request body into one string: t.body.
  3. Compute the HMAC-SHA256 of that string, using your signing secret as the key, and write it as lowercase hex.
  4. Compare the result with v1 using a constant-time comparison.
  5. Reject the request if t is more than five minutes old.
Use the body exactly as it arrived. If your framework parses the JSON and you turn it back into text, the bytes can differ and the signature will not match.
The signing secret is the whole string, including the whsec_ prefix.

Respond to an event

Answer with any 2xx status within 10 seconds. Anything else, including a redirect, counts as a failure. Do slow work after you respond. Save the event, return 200, and process it in the background.

Retries

If a delivery fails, CoinStack tries again after 1 minute, 5 minutes, 30 minutes, 2 hours, 5 hours, 8 hours and 8 hours. That is 8 attempts over about a day. After the last one, the event is not sent again unless you resend it.

Handle events safely

  • Expect duplicates. The same event can arrive more than once. Record each event_id you have handled and skip repeats, or make your handler safe to run twice.
  • Do not rely on order. Events can arrive out of order, and a retried event can arrive after a newer one. If the order matters, get the checkout when an event arrives and act on its current status.
  • Check that the checkout is yours. Match checkout_id to an order you created before you fulfil anything.

Test and resend

Send test on a webhook in the dashboard sends a sample checkout.completed event and shows whether your server accepted it. Send a test event does the same through the API. The sample checkout is for 10 US dollars and has the reference test. Under Recent events in the dashboard you can see each event, whether it was delivered, and send it again. List events and Resend an event do the same through the API.

Rotate the secret

If a signing secret may have leaked, select Rotate secret on the webhook in the dashboard, or call Rotate a webhook secret. The old secret stops working straight away, so update your server as soon as you have the new one.