Webhook configuration
An async handler: (request: Request) => Promise<Response>
// Supabase Edge Function / Deno
import { createWebhookHandler } from '@bates-solutions/squareup/server/web';
const handler = createWebhookHandler({
signatureKey: Deno.env.get('SQUARE_WEBHOOK_KEY')!,
notificationUrl: 'https://example.supabase.co/functions/v1/square-webhook',
handlers: {
'payment.updated': async (event) => {
await markPaid(event.data.id);
},
},
});
Deno.serve(handler);
// Cloudflare Workers
import { createWebhookHandler } from '@bates-solutions/squareup/server/web';
export default {
fetch(request: Request, env: { SQUARE_WEBHOOK_KEY: string }) {
return createWebhookHandler({
signatureKey: env.SQUARE_WEBHOOK_KEY,
notificationUrl: 'https://example.com/webhook',
handlers: {},
})(request);
},
};
Create a framework-neutral webhook handler built on the Web platform.
Takes a standard
Requestand returns a standardResponse, using only Web APIs (request.text(), WebCrypto verification via verifySignatureAsync,Response.json). Neither this module nor anything it imports uses a Node built-in. It runs unchanged on any runtime that speaks the Fetch API: Deno (Deno.serve), Supabase Edge Functions, Cloudflare Workers, Bun, Vercel/Netlify edge, and the Next.js App Router.Responses:
405for any method other thanPOST401when the signature header is missing or the signature is invalid500when the body is not JSON or a handler throws200with{ received: true, eventId }once the handler has runSquare signs
notificationUrl + rawBody, so setnotificationUrlto the exact URL registered on the webhook subscription.