Webhooks¶
Webhooks enable you to create an application or program that subscribe to a specific event regarding a new or updated transaction status in Digiflazz. once an event occured, we will send you a HTTP POST payload to the URL you have set in webhook configuration. Webhook can be used to do an update to your system in realtime, give notification, realtime graphics, data analytics, and etc.
You can configure your webhook on menu Connection configuration > API > Webhook.
Events¶
When you configure webhook, we will send an event regarding transaction (New & Update). This event will contain various detail data (Payload) of the transaction.
The available Events are:
Name | Description |
---|---|
create |
You will receive this event when there is a new transaction |
update |
You will receive this event when there is a change in status |
Payloads¶
Event we send will contains payload or relevant data of transaction information.
Delivery headers¶
HTTP POST payloads that will send to the webhook URL you have set will contain several special header:
Header | Description |
---|---|
X-Digiflazz-Event | Event type name that cause an event is sent |
X-Digiflazz-Delivery | An ID to indetify delivery |
X-Hub-Signature | A HMAC hex which come from body response. This Header will be sent if webhook is set on using secret . HMAC hex is the result of hash function sha1 and HMAC key . |
Besides that, request user-agent
will have prefix DigiFlazz-Hookshot
.
Example¶
POST /payload HTTP/1.1
Host: localhost:4567
X-Digiflazz-Delivery: dd320fc3-8dc8-49cb-a0d9-33aadacddc8a
X-Hub-Signature: sha1=7d6f016c23d03b696e76dada91c07f178cc0af4d
User-Agent: Digiflazz-Hookshot
Content-Type: application/json
Content-Length: 445
X-Digiflazz-Event: create
{
"data": {
"trx_id": "5ca22497cc6d0f965d9f84ac",
"ref_id": "30467470",
"customer_no": "017000001",
"buyer_sku_code": "maxis10",
"message": "Success",
"status": "Success",
"rc": "00",
"buyer_last_saldo": 4989.88,
"sn": "20190401214753214742",
"price": 10.12,
"tele": "@telegram",
"wa": "017000002"
}
}
Handle Event Example¶
Here is an example to receive an Event in PHP (Laravel)
<?php
use Illuminate\Http\Request;
Route::post('/webhook', function(Request $request) {
$secret = 'somesecretvalue';
$post_data = file_get_contents('php://input');
$signature = hash_hmac('sha1', $post_data, $secret);
\Log::info($signature);
if ($request->header('X-Hub-Signature') == 'sha1='.$signature) {
\Log::info(json_decode($request->getContent(), true));
}
});
Ping Event¶
When you decided on a webhook, we will send you a simple event ping
to tell you that your webhook is configure correctly and can be used. This event will not be stored, so it can not be taken through API. You will trigger a ping
by hitting Ping Endpoint
Ping Event Payload¶
Key | Value |
---|---|
sed | Random string from Digiflazz sed |
hook_id | ID from webhook that trigger a ping |
hook | Detail from your webhook configuration |
Ping Endpoint¶
https://api.my.digiflazz.com/v1/report/hooks/[YOUR-WEBHOOK-ID]/pings
Ping Example¶
> POST /v1/report/hooks/11aaabbb/pings HTTP/1.1
> Host: localhost:4567
> Accept: */*
> Content-Length: 0
< HTTP/1.1 200 OK
< Content-Length: 155
< Content-Type: application/json
{
"sed": "AgXXtVAHp",
"hook_id": "11aaabbb",
"hook": {
"url": "https://awesomesite.com/webhooks",
"secret": "somesecretkeywords",
"type": "application/json",
"status": 1
}
}