Webhooks¶
verify_signature ¶
verify_signature(
payload: bytes,
secret: str | bytes,
signature: str,
*,
header_prefix: str = "sha256=",
) -> None
Verify an HMAC-SHA256 webhook signature using constant-time comparison.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
payload
|
bytes
|
Raw request body bytes. |
required |
secret
|
str | bytes
|
Webhook signing secret (str or bytes). |
required |
signature
|
str
|
The value from the provider's signature header
(e.g. |
required |
header_prefix
|
str
|
Expected prefix on the signature value
(default: |
'sha256='
|
Raises:
| Type | Description |
|---|---|
WebhookVerificationError
|
If the signature does not match. |
Source code in merchants/webhooks.py
verify_khipu_signature ¶
Verify a Khipu v3.0 webhook signature (x-khipu-signature header).
Khipu signs webhooks with HMAC-SHA256 using the format
t=<unix_ms>,s=<base64_signature>. The signed message is
"<timestamp>.<body>".
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
payload
|
bytes
|
Raw request body bytes (the JSON as sent by Khipu — must not be re-serialised or whitespace-modified). |
required |
secret
|
str | bytes
|
Merchant secret (the Khipu receiver secret key). |
required |
header_value
|
str
|
The full |
required |
Returns:
| Type | Description |
|---|---|
str
|
The extracted timestamp string (useful for replay-attack checks). |
Raises:
| Type | Description |
|---|---|
WebhookVerificationError
|
If the header is malformed or the signature does not match. |
Source code in merchants/webhooks.py
parse_event ¶
Best-effort parse and normalisation of a raw webhook payload.
Tries to extract common fields (id, event_type/type,
payment_id, status) regardless of provider format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
payload
|
bytes
|
Raw request body bytes. |
required |
provider
|
str
|
Provider name hint for the returned event. |
'unknown'
|
Returns:
| Name | Type | Description |
|---|---|---|
A |
WebhookEvent
|
class: |
WebhookEvent
|
extracted are left as |