Hosted Checkout
Webhooks
Receive payment event notifications for hosted checkout
If a notification_url is provided in the payment request payload, Esenda will trigger a webhook:
- Whenever a transaction is updated (processing, accepted)
- When a transaction reaches a terminal state (success, failed, cancelled)
Updates for refunds and partial refunds are not sent via webhook for the Hosted Checkout. Contact your Esenda account manager or support@esenda.com if you need refund webhook support.
Esenda expects a 200 OK response. If not received, the webhook is retried up to 4 more times (5 attempts total).
Webhook Payload
{
"created_at": "2024-01-23 14:42:19.999462",
"data": {
"payment_id": "2d6586da-b5ad-4417-901a-c499dbdac774",
"payment_method": "card",
"status": "success",
"payment_reference": "reference",
"request_id": "6c6b77ba-fc4a-4a18-a1d9-5b2cdc2f8cdf"
},
"event_type": "payment.updated",
"id": "36bd6eea-9bad-4101-b3de-35389d348f9f",
"shortcode": "test-school"
}Payload Fields
| Field | Description | Example |
|---|---|---|
created_at | Created at timestamp | 2024-01-23 14:42:19.999462 |
data | Object containing the payment ID and status | See below |
data.payment_id | UUID payment identifier | UUID |
data.payment_method | Payment method used | card, open_banking |
data.status | Payment status | success, failed |
data.payment_reference | Payment reference | reference |
data.request_id | The request_id from your payment request | UUID |
event_type | Webhook event type | payment.updated |
id | Unique webhook identifier (UUID) | UUID |
shortcode | Organisation shortcode | test-school |
HMAC Signature Verification
All webhooks include an X-Hmac-Signature header. Use the webhook HMAC shared secret provided by Esenda with SHA-512 to verify authenticity.
Webhook Headers
Content-Type: application/json
X-Hmac-Signature: <hmac_signature>Validation Example (Python)
import hashlib
import hmac
import json
secret_key = SECRET_KEY_PROVIDED_BY_ESENDA
# Serialize the webhook body to a canonical JSON string
data_json = json.dumps(webhook_message, sort_keys=True, separators=(",", ":"))
# Calculate the HMAC-SHA-512 signature
expected_signature = hmac.new(
secret_key.encode("utf-8"), data_json.encode("utf-8"), hashlib.sha512
).hexdigest()
# Compare signatures securely
signatures_match = hmac.compare_digest(expected_signature, received_signature)