What is a webhook
the Webhook is a mechanism for receiving notifications when certain events occur on BezKassira on your own resource.
for Example, BezKassira there is a WebHook that allows you to track status changes on orders. It is called each time you change information in the order. Essentially what happens is, the order data are placed in JSON and sent to the URL specified in the settings of the organization.
How to use WebHook
To use enough to register in the organization configuration URL, which will send a POST request. Data filled by the service Administration.
After that, when changing the status of a ticket to your organization — for example, during registration or payment — will run a POST request to the address that you specified in the settings.
How to read WebHook
BezKassira sends WebHook method POST
with JSON
object in the request body. Also we sign the WebHook using hmac, which allows Your applications to ensure that the data we sent it.
Example of reading webhook'and in PHP
<?php
// Read the contents of a POST request
$body = @file_get_contents("php://input");
// Read the contents of the headers
$headers = getallheaders();
// Generated code, which must be signed WebHook
$sha1 = hash_hmac('sha1', $body, 'secret_key');
// Compare received code signature, so that came with WebHook
if ($sha1 == $headers['HTTP_X_HUB_SIGNATURE']) {
// WebHook came from the service BezKassira
print_r(json_decode($body, true));
}
?>
the content of the JSON request to WebHook
hook_type |
WebHook |
|
request Body depending on the WebHook type:
|
status |
Code execution |
0 - the request was successful |
status_message |
Decoding code execution |
Appears if a completion code is nonzero. |
How to respond to WebHook
Host WebHook script in case of success must meet the http status code 200
. When you receive any other code BezKassira considers the attempt to send data failed.
In such cases, the request will be sent to the same address with the same data hour. If this attempt also failed, the next one will take place on day. After that, the query is removed from the queue, even if the delivery did not take place.