Webhook configuration
Handler function that processes raw webhook requests
const handleWebhook = createWebhookProcessor({
signatureKey: process.env.SQUARE_WEBHOOK_KEY!,
handlers: {
'payment.created': async (event) => {
await sendReceipt(event.data.object.payment);
},
'order.updated': async (event) => {
await updateOrderStatus(event.data.object.order);
},
},
});
// Use in your route handler
const result = await handleWebhook(rawBody, signature);
Create a webhook handler function that verifies and processes events