Payments
Webhooks
A webhook is a message Overflow sends to your server when something happens to a payment. It is the only reliable way to know a buyer paid.
Set it up
- Add a route to your server that accepts
POSTrequests. - Under Developers → Webhook endpoints, add its public address. It has to be
https. - Copy that endpoint's signing secret into an environment variable.
- Press Send test event. A
webhook.testevent arrives, so you can check your route before a real payment.
A store can have up to 5 endpoints, for example one for your shop and one for your accounting. Each gets its own secret, and can be limited to the events it needs. With none ticked it gets every event. Turn an endpoint off to pause it without losing its settings.
Events
| Type | Sent when |
|---|---|
payment.succeeded | The money arrived. Fulfil the order now. |
payment.processing | The buyer confirmed a bank payment, such as SEPA Direct Debit. The money takes a few days. Wait for payment.succeeded or payment.failed before you deliver. |
payment.failed | A delayed payment method failed after the buyer confirmed. |
payment.blocked | The fraud gate turned the buyer away before any payment. |
payment.refunded | A full or partial refund went through. |
refund.failed | A refund didn't reach the buyer, for example because their card was closed. The amount counts as unrefunded again. data.refund has the reason. |
checkout.expired | The checkout ran out of time, or you expired it, before anyone paid. Release anything you held for it. |
payment.fraud_warning | The card issuer told Stripe this payment is probably fraud. A dispute often follows. |
dispute.opened | The buyer's bank reversed the payment, or asked about it first. For a question, data.dispute.status starts with warning_. |
dispute.closed | The dispute ended. data.dispute.status is Stripe's final status: won, lost, or warning_closed for a question that never became a chargeback. |
subscription.created | A buyer subscribed to a product that charges every period. data.subscription is the subscription. |
subscription.updated | A subscription moved to its next period, was set to end at the end of this one, or changed status, for example to past_due. |
subscription.canceled | A subscription ended. |
subscription.payment_failed | A renewal didn't go through. Stripe retries, and the buyer is asked by email to update their card. data.next_attempt says when. |
webhook.test | You pressed Send test event. Only that endpoint gets it. data.message says so. |
Payload
{
"id": "evt_Qk3b...",
"type": "payment.succeeded",
"created": 1796435822,
"livemode": true,
"data": {
"checkout": {
"id": "co_xv6n...",
"object": "checkout",
"status": "paid",
"amount": 1900,
"currency": "eur",
"customer_email": "buyer@example.com",
"metadata": {"order": "1001"},
"risk": {
"verdict": "allow",
"score": 0,
"reasons": [],
"radar_level": "normal",
"three_d_secure": "authenticated"
},
"refunded_amount": 0,
"paid_at": 1796435820
}
}
}data.checkout is the same checkout object the API returns. Each renewal of a subscription is a checkout of its own with kind set to renewal and subscription set, and sends payment.succeeded like any payment. Dispute events add data.dispute with the Stripe dispute id, reason, amount and status. payment.fraud_warning adds data.fraud_type.
Verify the signature
Anyone can post to your webhook address, so check every message before you act on it. Overflow signs the way the Standard Webhooks spec describes.
Each request carries three headers:
| Header | Value |
|---|---|
webhook-id | The event id. The same id on every retry, and on every endpoint that gets the event. |
webhook-timestamp | When this attempt was sent, in seconds. |
webhook-signature | v1, followed by a base64 HMAC-SHA256. Right after you roll a secret there are two, separated by a space : one for the new secret, one for the old. |
The signed text is {webhook-id}.{webhook-timestamp}.{raw body}. The key is the part of your secret after whsec_, base64-decoded. Accept the message if any of the signatures matches.
import {createHmac,timingSafeEqual} from "crypto"
export function verify(rawBody,headers,secret) {
const id = headers.get("webhook-id")
const ts = headers.get("webhook-timestamp")
const got = headers.get("webhook-signature") || ""
const key = Buffer.from(secret.replace("whsec_",""),"base64")
const want = "v1," + createHmac("sha256",key).update(`${id}.${ts}.${rawBody}`).digest("base64")
if (Math.abs(Date.now() / 1000 - Number(ts)) > 300) return false
return got.split(" ").some(sig => sig.length == want.length && timingSafeEqual(Buffer.from(sig),Buffer.from(want)))
}import base64, hashlib, hmac, time
def verify(raw_body: bytes, headers, secret: str) -> bool:
msg_id, ts = headers["webhook-id"], headers["webhook-timestamp"]
key = base64.b64decode(secret.removeprefix("whsec_"))
signed = f"{msg_id}.{ts}.".encode() + raw_body
want = "v1," + base64.b64encode(hmac.new(key, signed, hashlib.sha256).digest()).decode()
if abs(time.time() - int(ts)) > 300:
return False
return any(hmac.compare_digest(sig, want) for sig in headers.get("webhook-signature", "").split(" "))Three things go wrong most often:
- Verify the raw body. If your framework parses JSON first and you re-serialise it, the bytes change and the signature never matches.
- Reject old timestamps. Five minutes is plenty and stops a captured request from being replayed later.
- Compare in constant time. Use
timingSafeEqualorcompare_digest, not==.
Answer quickly, work safely
- Reply with any
2xxstatus within 8 seconds. Do slow work after you've answered. - Expect repeats. If your reply gets lost, the same event comes again with the same
id. Store the ids you've handled, or make fulfilment safe to run twice. - Events can arrive out of order. When it matters, fetch the checkout from the API for its current state.
Retries
A delivery that fails is retried after 1 minute, 5 minutes, 30 minutes, 2 hours, 6 hours and 24 hours: seven attempts over about 33 hours. Then it is marked failed, the endpoint shows as failing, and you get an email. It stops failing as soon as one delivery gets through.
Developers lists recent deliveries with the endpoint, your server's response code and the number of tries, and lets you send any that didn't arrive again.
Rolling a secret
Press Roll next to an endpoint's secret if it leaks or as routine. For the next 24 hours every message is signed with both the new and the old secret, so you can update your server without missing an event. After that only the new one signs.