Skip to main content
SolvaPay sends a signed JSON event to your endpoint when something happens, such as a purchase being created or a payment succeeding. VerifyWebhook checks the signature and parses the event. For the event catalogue and payload shapes, see Webhooks.

Prerequisites

  1. In SolvaPay Console, go to Settings > Webhooks and add your endpoint URL.
  2. Copy the signing secret (whsec_…) into SOLVAPAY_WEBHOOK_SECRET.

Receive events

main.go
VerifyWebhook(body, signature, secret, now) takes:
  • body: the request body exactly as received. Read it with io.ReadAll before anything decodes it. If the body is decoded and encoded again, the signature check fails.
  • signature: the SV-Signature header, t=<unix seconds>,v1=<hex HMAC>.
  • secret: the whole signing secret, including whsec_.
  • now: the time to check the timestamp against. The zero time.Time means the current time.
It returns the event as decoded JSON (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.
VerifyWebhook does not check that secret is set. With an empty secret, anyone can sign an event that verifies. Check the secret at startup, as the example does.

Next steps