Overview
PixelTech Colombia receives webhooks from multiple payment gateways and communication platforms. All webhooks are implemented as Firebase Cloud Functions with HTTPS endpoints.Webhook Architecture
Endpoint Pattern
All webhooks follow this URL structure:mercadoPagoWebhookaddiWebhook→ Deployed to Cloud Run:https://addiwebhook-muiondpggq-uc.a.run.appsistecreditoWebhook→ Deployed to Cloud Run:https://sistecreditowebhook-muiondpggq-uc.a.run.appwhatsappWebhook
Common Flow
MercadoPago Webhook
Configuration
Function:mercadoPagoWebhook
Type: HTTPS Request
File: functions/mercadopago.js:174
Endpoint: https://us-central1-pixeltechcol.cloudfunctions.net/mercadoPagoWebhook
Registered in: MercadoPago preference creation (functions/mercadopago.js:154)
Payload Format
MercadoPago sends minimal data in webhook:- Query params:
?id=1234567890&topic=payment - Body:
{ "id": "1234567890", "topic": "payment" }
Webhook Handler
Code:functions/mercadopago.js:174-326
Step 1: Extract Payment ID
Step 2: Verify Payment Status
Always verify with API (never trust webhook payload directly):Step 3: Process Payment (Approved)
Code:functions/mercadopago.js:204-306
Step 4: Handle Rejection
Testing MercadoPago Webhook
Local Testing with Emulator
Production Testing
Use MercadoPago’s Sandbox mode:- Approved: 4170 0688 1010 8020 (VISA)
- Rejected: 4013 5406 8274 6260 (VISA)
ADDI Webhook
Configuration
Function:addiWebhook
Type: HTTPS Request with CORS
File: functions/addi.js:260
Endpoint: https://addiwebhook-muiondpggq-uc.a.run.app
Registered in: Checkout creation (functions/addi.js:216)
Payload Format
APPROVED/COMPLETED: Payment successfulREJECTED/DECLINED/ABANDONED: Payment failed
Webhook Handler
Code:functions/addi.js:260-376
- ADDI sends full order data in webhook (no API verification needed)
- CORS enabled (ADDI makes cross-origin requests)
- Uses
paymentStatuscheck instead ofstatusfor duplicate prevention
Duplicate Prevention
Problem: ADDI sometimes sends multiple webhooks for the same payment. Solution (functions/addi.js:281-284):
paymentStatus: Financial state (always set first)status: Logistics state (might be updated later)
Testing ADDI Webhook
Sistecrédito Webhook
Configuration
Function:sistecreditoWebhook
Type: HTTPS Request with CORS
File: functions/sistecredito.js:172
Endpoint: https://sistecreditowebhook-muiondpggq-uc.a.run.app
Registered in: Checkout creation (functions/sistecredito.js:127)
Payload Format
Approved: Payment successfulRejected/Cancelled/Failed: Payment failed
Webhook Handler
Code:functions/sistecredito.js:172-289
Testing Sistecrédito Webhook
WhatsApp Webhook
Configuration
Function:whatsappWebhook
Type: HTTPS Request
File: functions/whatsapp.js:65
Endpoint: https://us-central1-pixeltechcol.cloudfunctions.net/whatsappWebhook
Registered in: Meta Developer Portal (WhatsApp Business API settings)
Verification Request
Meta sends GET request to verify webhook:functions/whatsapp.js:67-72):
Message Payload
Message Handler
Code:functions/whatsapp.js:75-173
Auto-Reply Bot
Code:functions/whatsapp.js:100-136
Active Hours: 8 PM to 7 AM (Colombia time)
Cooldown: 12 hours between auto-replies
Media Download
Helper (functions/whatsapp.js:40-62):
Testing WhatsApp Webhook
Verification Test
Message Test
Webhook Security
1. Verify Payment Status
Always verify with gateway API (MercadoPago example):2. Idempotency
Prevent duplicate processing with transaction checks:3. Signature Verification
WhatsApp Example (if Meta sends signature):4. Rate Limiting
Firebase Hosting rewrites with rate limits:Monitoring & Debugging
Cloud Functions Logs
Webhook Debugging
Add detailed logging in handlers:Webhook Testing Tools
Webhook.site: Create temporary endpointError Handling
Retry Logic
Most payment gateways retry webhooks on failure:- MercadoPago: Retries up to 12 times over 48 hours
- ADDI: Retries up to 5 times over 24 hours
- Sistecrédito: Retries up to 3 times over 6 hours
Dead Letter Queue
Store failed webhooks for manual review:Best Practices
- Always return 200 OK (even on errors) to prevent retry storms
- Verify payment status with gateway API (never trust webhook payload alone)
- Use transactions for database updates (prevent partial updates)
- Check for duplicates before processing (idempotency)
- Log everything (webhooks are hard to debug)
- Test with real webhooks (emulator behavior differs from production)
- Monitor failure rates (set up alerts for over 5% failures)
- Keep handlers fast (under 10 seconds execution time)
- Use Cloud Run for CORS-enabled webhooks (ADDI, Sistecrédito)
- Document payload formats (payment gateways change without notice)