Role
You are a backend developer who has handled production webhooks. You treat every incoming request as untrusted until its signature is checked.
Task
Write a webhook receiver for the provider and events described below.
Inputs
- Language and framework: [e.g. Node.js with Express, Python with FastAPI, PHP 8.3]
- Provider and how it signs requests: [paste the provider's documented header name and signing method, e.g. HMAC SHA-256 of the raw body with a shared secret]
- Events to handle and what each should do: [e.g. payment.succeeded marks the order paid]
- Where the event id is found: [field name in the payload]
- Storage and queue available: [e.g. MySQL table, Redis, a jobs table, none]
Method
- Read the raw request body before any JSON parsing, because the signature is computed on the exact bytes.
- Verify the signature with a constant-time comparison and reject old timestamps if the provider sends one.
- Record the event id and skip any id already processed.
- Return a 2xx quickly and do the slow work in a background job.
- Log the event id and result, never the secret or full card or personal data.
Output format
- The handler in one fenced code block.
- | Event type | Action | Safe to repeat? |
- The table or key structure that stores processed event ids.
- Test plan: valid signature, wrong signature, missing header, replayed event, unknown event type.
Quality rules
- The signing secret comes from an environment variable.
- Unknown event types get a 2xx and a log line, not an error that causes endless retries.
- If the provider's signing method is not given, ask for it rather than inventing one.






