Webhook Signature Verifier
Test and verify webhook signatures before implementing in production. Learn how to properly validate incoming webhooks from HooPay.
Verify Webhook Signature
Implementation Examples
import hmac
import hashlib
import time
def verify_webhook(payload, signature, timestamp, secret):
# Check timestamp is within 5 minutes
if abs(time.time() - int(timestamp)) > 300:
return False
# Create signed payload
signed_payload = f"{timestamp}.{payload}"
# Compute expected signature
expected = hmac.new(
secret.encode('utf-8'),
signed_payload.encode('utf-8'),
hashlib.sha256
).hexdigest()
# Constant-time comparison
return hmac.compare_digest(signature, expected)
Webhook Events
payment.completed
Payment successful
payment.failed
Payment failed
payment.cancelled
Session cancelled
payment.completed
Payment settled
collection.completed
Collection processed
Best Practices
- Always verify signatures before processing webhooks
- Respond with 2xx status within 5 seconds
- Process webhooks asynchronously (queue them)
- Store webhook_id to handle duplicates
- Use constant-time comparison for signatures