Setup
Pass your webhook public key when initializing the SDK:environment.
Verify and Parse
The signature covers the exact bytes Afriex sent, so verify the raw request body. If a JSON body parser such asexpress.json() runs first, you get a parsed object instead of the bytes Afriex signed, and every signature check fails. In Express, read the webhook route with express.raw() and pass the body to the SDK as it is. verify and verifyAndParse take a Buffer or a string:
Store each event before you acknowledge it, and act on it afterwards, outside the request. Afriex waits up to 15 seconds for a 2xx, retries anything slower, and sends every event at least once, so key what you store on the event’s id. See Duplicates, ordering, and replays.
id and createdAt are part of every webhook body. The SDK’s WebhookPayload type includes them from the first release after @afriex/sdk 5.0.0. On 5.0.0, upgrade, or read them from the parsed JSON.Verify Only
Validate the signature without parsing.payload is the raw body, as above:
Trigger Test Webhook (Sandbox)
Send a test webhook to your endpoint in sandbox:CHECKOUT_SESSION.CREATED, use the checkoutId returned when you created the checkout as resourceId.
Test webhook triggers only work in the sandbox environment.
