Webhooks
Create webhook
To create a webhook:
- in the Panel, go to Settings and click on the Api Here you can also view if you have API access to integrate with vouchstar
- Provide
Domain
- Provide
Target path
- Copy the
secret key
to be used to calculate the digest with the HMAC algorithm
Verify webhook sender
To make sure the webhook is sent by Vouchstar, we sign it with the HMAC algorithm.
To verify the webhook sender:
- Recieve the webhook body sent by http method POST to
domain-target-path
set while creating the webhook - Request body will be defined as
WebhookRequest
- Generate the digest with the raw
WebhookPayload
- Compare the
signature
from theWebhookRequest
that you received with the generated digest from step 3 - On successful signature match, you should respond with HTTP response status code
200 OK
with body content{"activate": "OK"}
Generate the signature
To generate the digest, the folowing actions should be applied:
- Simple parameters should be converted to format:
paramter=value
eg.currency=USD
- Objects parameters should be converted to format:
objectName.parameter=value
eg.user.email=test@email.com
- Whole list should be converted to lowercase
- List should be sorted in alpabetical order
- Sorted parameters should be connected with
&
- Generate the HMAC with the
secret key
and the prepared signature data from steps 1 - 5 with hash functionSHA-512
Formula
signature = signatureAlgorithm(key=value&key1=value1&...&keyN=valueN);
Full example
Signature data: additional='testing-id' voucher_id='8837104d-3ba7-434d-81c3-0c5f290c1abb' price='20.0' currency='USD' user=SignatureUser(email='example@vouchstar.shop') status='USED' created_at='2024-08-26 11:39:42'Prepared signature data: additional=testing-id&created_at=2024-08-26 11:39:42¤cy=usd&price=20.0&status=used&user.email=example@vouchstar.shop&voucher_id=8837104d-3ba7-434d-81c3-0c5f290c1abbRetrieved mac: vs-sadfhjkhasdjkfbnjaksf7as6f7a8fd78HMAC SHA-512: 9804a15ec1ef9d2602296237cafde471fdb2990073e34670011e421079b61f582577615e5c937f00cb77379a3543f474e871788376ce30e6487d694e2a8915b0