Kyrrex pay Webhooks utilizes Signature Token for signing Requests which sends to Webhook Targets. Webhooks are divided into general and webhooks related to payment pages. You can get your Signature Token on Tokens Project page in page Settings for general webhook settings.
General webhook settings
In order to receive invoice statuses, you need to insert the URL for the webhook, there must be a POST endpoint.
const webhookPayload = {
invoiceId: invoice.id,
status: invoice.status,
receivedAmount: invoice.receivedAmount,
txHash: invoice.txHash,
passthrough: invoice.passthrough,
};
Also in headers there will be a key:
headers: {
'Content-Type': 'application/json',
'x-kpay-sig': signature,
},
X-pay-sig this is a hashed payload. Hashed using the following function:
export function encode_hmac_for_kpay(
notificationsKey: string,
params: any,
): string {
const sortedParams = Object.keys(params)
.sort()
.reduce((obj, key) => {
obj[key] = params[key];
return obj;
}, {});
const sortedJson = JSON.stringify(sortedParams, null, null);
const hmac = createHmac('sha512', notificationsKey.trim());
hmac.update(sortedJson);
return hmac.digest('hex');
}
notificationsKey – your private key
Params – it's payload this we are sending
Security Tip!!!
We recommend using the function above to hash the payload using the private key from your personal account. For each request, compare it with the hash that came in 'x-kpay-sig', so that in case of hacking, attackers cannot steal your funds.