Webhook configuration
Express middleware function
import express from 'express';
import { createExpressWebhookHandler } from '@bates-solutions/squareup/server';
const app = express();
// IMPORTANT: Use raw body parser for webhook route
app.use('/webhook', express.raw({ type: 'application/json' }));
app.post('/webhook', createExpressWebhookHandler({
signatureKey: process.env.SQUARE_WEBHOOK_KEY!,
handlers: {
'payment.created': async (event) => {
console.log('Payment created:', event.data.id);
},
},
}));
Create Express middleware for handling Square webhooks
This middleware: