API Integration
Webhooks
Receive real-time transaction updates
Webhooks
Receive notifications when a transaction is approved.
Overview
- Trigger: Transaction status changes to
APPROVED - Method: POST to your configured URL
- Retry: 3 attempts with exponential backoff (5s, 10s, 15s)
- Response: Return
2xxstatus code
Webhook Request
Headers
| Header | Description |
|---|---|
Content-Type | application/json |
X-Alya-Event-Id | Unique event ID (UUID) |
X-Alya-Timestamp | ISO 8601 timestamp |
X-Alya-Signature | HMAC-SHA256 signature |
Payload
{
"event": "transaction.approved",
"timestamp": "2024-12-08T10:30:00Z",
"data": {
"id": "550e8400-e29b-41d4-a716-446655440000",
"vendorReference": "ORDER-2024-001",
"orderReference": "AB12345",
"status": "APPROVED",
"amount": 500.00,
"currency": "MAD",
"customerPhone": "212612345678",
"merchantName": "My Store",
"storeName": "Downtown Branch",
"createdAt": "2024-12-08T10:25:00Z"
}
}Signature Verification
The signature is computed as:
signature = HMAC-SHA256(webhookSecret, timestamp + "." + payload)Header format: X-Alya-Signature: sha256={hex_signature}
Handling Webhooks
- Verify signature - Always validate the signature
- Return 200 quickly - Acknowledge receipt immediately
- Process asynchronously - Handle business logic after responding
- Check for duplicates - Use
X-Alya-Event-Idto prevent duplicate processing - Validate timestamp - Reject webhooks older than 5 minutes
Event Types
| Event | Description |
|---|---|
transaction.approved | Customer approved payment |
test | Test webhook from dashboard |
Best Practices
- Use HTTPS for webhook URLs
- Return
2xxstatus code within 10 seconds - Store
X-Alya-Event-Idto prevent duplicate processing - Implement idempotent handlers
- Verify signature on every webhook