/ Cases / Tourism / Payments
Orders and payments with Stripe, Recurrente, Tilopay and PayPal, the Banguat (Guatemala's central bank) exchange rate, payment links with a branded checkout page and WhatsApp notices with no duplicates.
4
gateways
3
businesses
2
currencies
/ The problem
Three businesses, four gateways and two currencies, each one charging its own way and reconciling by hand.
/ What we built
/ How it works
/ Real code
// 1. RAW body antes de parse (firma se valida sobre el body literal).
const rawBody = await request.text();
// 2. Verify via adapter.
const adapter = await getAdapter(gateway);
let event: WebhookEvent;
try {
event = await adapter.verifyWebhook(request.headers, rawBody);
// …
// 3. Firma falló → registrar para forensics + 401.
if (!event.signature_ok) {
console.warn('[webhook]', gateway, 'signature INVALID for event', event.event_id);
// …
return new Response('signature invalid', { status: 401 });
}
const supabase = createServiceClient();
// 4. Idempotencia.
const { data: existing } = await supabase
.from('payment_events')
.select('id, processed')
.eq('gateway', gateway)
.eq('event_id', event.event_id)
.maybeSingle();
if (existing?.processed) {
return new Response('already processed', { status: 200 });
}
■ One handler for every gateway: signature checked on the raw body, forged attempts logged for forensics and each event processed only once.
/ Stack