Webhooks push events to your server in real-time. No polling needed.
Copy
Your App <-- Webhook <-- Waffo Pancake
When an event occurs (order completed, subscription activated, etc.), Waffo Pancake sends an HTTP POST request to your registered endpoint with the event data.
Return 200 OK quickly. Process asynchronously if your handler needs to do heavy work.
Copy
import { verifyWebhook, WebhookEventType } from "@waffo/pancake-ts";export async function POST(req: Request) { const body = await req.text(); const signature = req.headers.get("x-signature") ?? ""; const timestamp = req.headers.get("x-timestamp") ?? ""; // Built-in signature verification — no webhook secret needed const { event, data } = verifyWebhook({ body, signature, timestamp, environment: "test", // or "prod" }); switch (event) { case WebhookEventType.OrderCompleted: await handleOrderCompleted(data); break; case WebhookEventType.SubscriptionActivated: await handleSubscriptionActivated(data); break; case WebhookEventType.SubscriptionPaymentSucceeded: await handleSubscriptionPaymentSucceeded(data); break; case WebhookEventType.SubscriptionCanceling: await handleSubscriptionCanceling(data); break; case WebhookEventType.SubscriptionCanceled: await handleSubscriptionCanceled(data); break; case WebhookEventType.SubscriptionPastDue: await handleSubscriptionPastDue(data); break; case WebhookEventType.RefundSucceeded: await handleRefundSucceeded(data); break; case WebhookEventType.RefundFailed: await handleRefundFailed(data); break; } return new Response("OK", { status: 200 });}
The TypeScript SDK’s verifyWebhook() function handles signature verification with embedded public keys for both test and production environments. No webhook secret configuration needed — just pass the request body, signature header, timestamp header, and environment.
Events may be delivered more than once. Use the event data (such as the order or payment ID) for deduplication to ensure your handler processes each event only once.
Copy
const processedEvents = new Set();app.post('/webhooks/waffo', (req, res) => { const { event, data } = req.body; const eventKey = `${event}:${data.id}`; if (processedEvents.has(eventKey)) { return res.status(200).send('Already processed'); } processedEvents.add(eventKey); res.status(200).send('OK'); // Process the event processWebhook(event, data);});
For production, store processed event IDs in a database instead of in-memory to persist across server restarts.
Use Test Mode to send test events to your webhook endpoint:
Switch to Test Mode in the Dashboard header
Go to Developers —> Webhooks
Perform actions (create orders, complete payments) in test mode
Check your endpoint for incoming webhook events
Webhooks fire in both Test and Live modes. Make sure your endpoint can distinguish between test and live events using the X-Environment context of the original action.