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: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
eventsout 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 aPOST 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. TheCoinStack-Signature header looks like this:
t is the time the request was signed, in Unix seconds. v1 is the signature. To check it:
- Read
tandv1from the header. - Join
t, a full stop and the raw request body into one string:t.body. - Compute the HMAC-SHA256 of that string, using your signing secret as the key, and write it as lowercase hex.
- Compare the result with
v1using a constant-time comparison. - Reject the request if
tis more than five minutes old.
whsec_ prefix.
Respond to an event
Answer with any2xx 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_idyou 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_idto an order you created before you fulfil anything.
Test and resend
Send test on a webhook in the dashboard sends a samplecheckout.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.