VerifyWebhook checks the signature and parses the event. For the event catalogue and payload shapes, see Webhooks.
Prerequisites
- In SolvaPay Console, go to Settings > Webhooks and add your endpoint URL.
- Copy the signing secret (
whsec_…) intoSOLVAPAY_WEBHOOK_SECRET.
Receive events
main.go
VerifyWebhook(body, signature, secret, now) takes:
body: the request body exactly as received. Read it withio.ReadAllbefore anything decodes it. If the body is decoded and encoded again, the signature check fails.signature: theSV-Signatureheader,t=<unix seconds>,v1=<hex HMAC>.secret: the whole signing secret, includingwhsec_.now: the time to check the timestamp against. The zerotime.Timemeans the current time.
map[string]any, with numbers as json.Number). Return a 2xx once you have handled it.
Errors
A failed check returns a*solvapay.Error with one of these codes:
The codes are constants too:
solvapay.WebhookSecretMissing, WebhookSignatureMissing, WebhookSignatureMalformed, WebhookTimestampOutOfRange, WebhookSignatureInvalid and WebhookPayloadInvalid.
Next steps
- Webhooks: every event type and its payload.
- The TypeScript equivalent of this page: Webhook handling.