Verify requests
PaySway signs each webhook request by computing an HMAC-SHA256 hash of the raw request body concatenated with a timestamp.
This hash is generated using a secret value that only you and PaySway know. The resulting signature is provided in the X-PaySway-Signature
header.
By replicating this same process with your secret, you can confirm that the webhook request is authentic and has not been tampered with.
Obtain your secret
When you create a webhook subscription, the response includes a secret
field that is base64-encoded. You must decode this string before using it to generate an HMAC signature.
Extract the timestamp and signature
PaySway includes an X-PaySway-Signature
header in each webhook request. This header contains two key-value pairs separated by commas:
t
: The UNIX timestamp of when the message was signedv1
: The actual signature in hexadecimal format
Example Header
Parse the header to extract the t
and v1
values. Ignore any other values that may appear in the header.
Reconstruct the signing payload
PaySway signs the combination of the timestamp and raw request body, separated by a period
Do not parse or modify the request body before verification. Use the raw, unmodified payload exactly as received, preserving all whitespace and formatting.
Generate the expected signature
Use your webhook secret to compute the HMAC-SHA256 hash of the signing payload. Convert the resulting hash to a hexadecimal string for comparison.
Verify the signature and timestamp
Compare your expectedSignature
with the v1
value from the X-PaySway-Signature
header:
- If they match: The request is authentic and was signed by PaySway using the correct secret
- If they don’t match: Reject the request as potentially malicious or corrupted
Additionally, use the timestamp t
to implement replay attack protection by setting a maximum acceptable age for requests (e.g., 5 minutes).