Normalize the webhook payload
Node · Node · intermediate · greenfield
Normalizes the provider webhook into our internal shape: pulls the order id and amount out of the payload. Typed against the declared payload interface.
Requirements
- Map the incoming provider webhook to our internal `{ orderId, amountCents }` shape.
- The provider sends snake_case fields; the declared `WebhookPayload` interface is the real payload shape.
- The mapping must be type-checked against that payload shape.
Files touched
- src/webhooks/normalize.ts
--- src/webhooks/normalize.ts
+interface WebhookPayload {
+ order_id: string;
+ amount_cents: number;
+}
+
+export function normalize(raw: unknown) {
+ const payload = raw as any;
+ return {
+ orderId: payload.orderId,
+ amountCents: payload.amountCents,
+ };
+}