From 156973e3cc05a02d2739c3adb8e6375fc1f23014 Mon Sep 17 00:00:00 2001 From: AbdulmujibOladayo Date: Fri, 11 Sep 2026 08:01:09 +0100 Subject: [PATCH] docs: add webhook setup and usage documentation --- docs/webhooks.md | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 docs/webhooks.md diff --git a/docs/webhooks.md b/docs/webhooks.md new file mode 100644 index 0000000..4e09b1f --- /dev/null +++ b/docs/webhooks.md @@ -0,0 +1,33 @@ +# Webhooks + +PayStream can notify your service of payment status changes via signed +HTTP webhooks, delivered by `internal/webhook`. + +## Registering an endpoint + +An `Endpoint` pairs a destination URL with a secret used to sign payloads: + +```go +ep := webhook.Endpoint{ + URL: "https://example.com/hooks/paystream", + Secret: "your-webhook-secret", +} +``` + +## Delivery and retries + +`Notifier.Send` posts a JSON-encoded `Event` to the endpoint, retrying +non-2xx responses and transport errors with exponential backoff (default +3 retries, starting at a 1 second delay): + +```go +n := webhook.NewNotifier() +err := n.Send(ctx, ep, webhook.Event{Type: "payment.completed", Data: payload}) +``` + +## Verifying signatures + +Every request includes an `X-PayStream-Signature` header: the hex-encoded +HMAC-SHA256 of the raw request body, keyed with your endpoint's secret. +Recompute it with `webhook.Sign(secret, body)` and compare before trusting +the payload. The event type is also sent as `X-PayStream-Event`.