v1
latestOpenAPI 3.0.02026-08-06363576.8 KBWebhook calls
Called when subscription changed or renewed
We recommend that you verify all calls from us to your webhook endpoints. We sign each request with the Hook-HMAC header. The value is a HMAC digest derived from the body of the request and a secret key only known by the API and you. We also supply the type of event in the Hook-Event header.
Here is a sample implementation in Python. This process is very similar to the one Shopify uses so more information can possibly be gleaned from their documentation.
import base64
import hmac
import hashlib
WEBHOOK_SECRET = "Your webhook secret".encode()
WEBHOOK_DIGEST_TYPE = 'sha512'
def verify(hmac_header, digest_method, secret, message):
digestmod = getattr(hashlib, digest_method)
signed = base64.b64encode(
hmac.new(secret, message, digestmod).digest(),
).strip()
return hmac.compare_digest(signed, hmac_header)
# your view function
def handle_webhook(request):
# The signature
digest = request.META.get('HTTP_HOOK_HMAC').encode()
# The name of the webhook event
event = request.META.get('HTTP_HOOK_EVENT').encode()
body = request.body
if verify(digest, WEBHOOK_DIGEST_TYPE, WEBHOOK_SECRET, body):
payload = json.loads(body)
# ... the rest of your code here```
post/your-webhook-url/
Request body
Example request
{
"customer": {
"first_name": "Jón",
"last_name": "Jónsson",
"email": "email@example.com",
"phone": "+3545551234",
"customer_reference": "1234",
"id": 1,
"payment_method": [
{
"verified": true,
"valid_until": "2022-11-01T00:00:00Z",
"display_info": "XXXX-XXXX-XXXX-2887 (MasterCard)"
}
]
},
"subscriptions": [
{
"id": 123,
"reference": "REF-12345",
"token": "637302f0412e2e11adc0ba21adafcf11",
"customer": {
"first_name": "Jón",
"last_name": "Jónsson",
"email": "email@example.com",
"phone": "+3545551234",
"customer_reference": "1234",
"id": 1,
"payment_method": [
{
"verified": true,
"valid_until": "2022-11-01T00:00:00Z",
"display_info": "XXXX-XXXX-XXXX-2887 (MasterCard)"
}
]
}
}
]
}Response
Successful operation