The Bridge (Webhooks)
Master real-time event-driven architecture with SamaPay's signature engine.
The Bridge is a world-class webhook engine designed for the high-availability needs of Gambian fintech. It pushes payment status, settlement triggers, and reversal events directly to your server in real-time.
Event Life-Cycle
- Payment Success: User completes a Wave or Bank transaction.
- Dispatch: SamaPay constructs a cryptographically signed payload.
- Delivery: Outgoing POST is sent to your configured "Bridge URL".
- Verification: Your server validates the
Sama-Signatureand acknowledges (200 OK).
Advanced Implementation (Node.js)
const express = require('express');
const crypto = require('crypto');
const app = express();
const SAMA_WEBHOOK_SECRET = process.env.SAMA_WEBHOOK_SECRET;
app.post('/samapay/webhook', express.raw({type: 'application/json'}), (req, res) => {
const signature = req.headers['sama-signature'];
const payload = req.body;
// 1. Verify Platform Authenticity
const hmac = crypto.createHmac('sha256', SAMA_WEBHOOK_SECRET);
const digest = hmac.update(payload).digest('hex');
if (signature !== digest) {
return res.status(401).send('Invalid platform signature');
}
// 2. Process Business Logic
const event = JSON.parse(payload);
console.log(`Processing ${event.type} for Order: ${event.data.metadata.order_id}`);
res.json({ received: true });
});
Testing Scenarios (Simulator)
| Scenario | Logic Path | Expected Webhook |
|---|---|---|
| Full Success | User pays 5,000 GMD | payment.success |
| Insufficient Balance | Wave returns error | payment.failed |
| Manual Reversal | Merchant clicks Refund | refund.processed |
| Auto-Settlement | Rule met (GMD 10k) | payout.initiated |
Reliability Features
- Retries: If your server is down, we retry with exponential backoff for up to 24 hours.
- Idempotency: Every event includes a unique
event_idto prevent duplicate processing. - Payload Versioning: We use dated versions to ensure your integration never breaks unexpectedly.