/ Cases / Tourism / Payments

One payment engine for three businesses and four gateways

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.

/ Restaurantes · Experience · Atitlán's House/ 2026/ Signed webhooks · card in an iframe (PCI SAQ A)

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

  • A single order and payment engine shared by three businesses.
  • Stripe, Recurrente, Tilopay and PayPal; Banguat exchange rate.
  • Payment links with a branded checkout page; the dashboard shows who opened it and didn't pay.
  • The card is captured in the gateway's iframe; signed webhooks to the other systems.

/ How it works

  1. 01Order
  2. 02Link or checkout
  3. 03Gateway
  4. 04Signed webhook
  5. 05Notice and accounting entry

/ Real code

src/lib/payments/handle-webhook.tsts
  // 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

StripeRecurrenteTilopayPayPalCloudflare WorkersHMAC