Skip to content

Search documentation

Find a page of the Sovgate documentation and jump straight to it.

Receive events with webhooks

Add an endpoint on your server, choose the events it listens to, and check each delivery's Sovgate-Signature.

A webhook endpoint is a URL on your server that Sovgate sends events to as they happen, such as checkout.session.completed when a customer pays. Each delivery is signed, so your server can check it came from Sovgate.

Add an endpoint

Start

Go to Developers, Webhooks and choose Add endpoint. It's added in the mode you're in.

Enter the URL

The https:// address on your server that receives the events, with an optional description.

Choose the events

Pick only the events your server uses, such as payment.succeeded, refund.failed, dispute.created, invoice.paid or subscription.payment_failed.

Copy the signing secret

Each endpoint has its own signing secret, starting whsec_. Reveal it on the endpoint's page and put it in your server's environment.

Send a test event

Choose Send test event to check your server answers. A test event goes to this endpoint only, isn't retried and isn't counted in its health.

Each mode can have up to 16 endpoints.

Answer each delivery

Your server must answer with a 2xx status within 15 seconds. Anything else, or no answer in time, is a failed attempt, and the delivery is retried. Answer first, then do the work: a slow job shouldn't hold the answer back.

The same event can arrive more than once, so make your handler safe to run twice: check the event's ID, or the object's state, before you act on it.

Check the signature

Every delivery carries a Sovgate-Signature header:

Sovgate-Signature
text
t=1764158400,v1=5257a869e7ecebeda32affa62cdca3fa51cad7e77a0e56ff536d0ce8e108d8bd

Read the header

t is when the attempt started, in Unix seconds. Each v1 is a signature, one per signing secret in use.

Compute the expected signature

An HMAC-SHA256, keyed with your signing secret, of t, a dot, and the raw request body exactly as received, in hex.

Compare

Accept the delivery if any v1 matches, using a constant-time comparison, and reject a t that's too old, to stop replays.

verify.js
javascript
import crypto from "node:crypto"
function verify(rawBody, header, secret, toleranceSeconds = 300) { const parts = header.split(",").map((part) => part.split("=")) const t = parts.find(([key]) => key === "t")?.[1] const signatures = parts.filter(([key]) => key === "v1").map(([, value]) => value) if (!t || Math.abs(Date.now() / 1000 - Number(t)) > toleranceSeconds) return false const expected = crypto.createHmac("sha256", secret).update(`${t}.${rawBody}`).digest("hex") return signatures.some( (signature) => signature.length === expected.length && crypto.timingSafeEqual(Buffer.from(signature), Buffer.from(expected)) )}

Roll the signing secret

Choose Roll secret:

  • Replacing it on schedule: the old secret keeps signing beside the new one for the time you choose, so your server can move to it. Each delivery then carries a signature from both. Expire previous now ends the overlap early.
  • It may have been exposed: the old secret stops at once, and deliveries fail at your server until you deploy the new one. Failed deliveries are retried on schedule, and can be resent for 15 days.