Webhooks

Notification webhooks

You can use webhooks for extending default Ordering Stack notifications functionality. Thanks to this you can handle sending onOrderCompleted and onOrderReady messages to the user. In order to receive webhooks from Ordering Stack you need to set your webhook URL in the Tenants Settings for the property orderChangeWebhook-CompleteOrderEventCommand and orderChangeWebhook-OrderDeliverReadyEventCommand .

CompleteOrderEventCommand

When order is completed (items added and order has assigned payment items that sums to order value) order is marked as completed. For this event Ordering Stack performs POST request to specified webhook url passing order in the JSON format in the request body. Example request performed on the webhook:

POST {{webhook_url}}
Accept: application/json
Content-Type: application/json

{
    "commandClass":"OrderCompletedEventCommand",
    "command": {
        "status": "COMPLETED"
    },
    "tenant": {
        "__NAME__": "test",
        "defaultLanguage" : "pl",
        "currency" : "EUR"
    },
    "order": {
    "id" : "3916a504-6312-417f-b8ad-17e1ca74f5c1",
    "tenant" : "8724ef73-20c8-4018-b183-3504cadc38bf",
    "closedDate" : "2019-08-27T10:47:43",
    "lastChanged" : "2019-08-27T10:47:43",
    "isClosed" : true,
    "isCompleted" : true,
    "source" : "central",
    "users" : [ 
        {
            "userId" : "7d47b7bc-0bb7-4493-8cd9-aaad630eb02d",
            "roles" : [ 
                "CUSTOMER", 
                "CREATOR"
            ],
            "phone": "48123456789",
            "email":"example@example.com",
            "extra" : {}
        }
    ],
    "orderType" : "TAKE_AWAY",
    "total" : "13.99",
    "editTotal" : "13.99",
    "status" : "COMPLETED",
    "statusInfo" : "completed",
    "claimCode" : "YQ0W5O",
    "buckets" : [ 
        {
            "venue" : "2de9a0c3-4b21-407c-83d1-031ea0735eb3",
            "sync" : false,
            "name" : "Burger",
            "lines" : [ 
                {
                    "id" : "36ca0d9e-8589-42e9-bee3-4f6c49efe95f",
                    "creator" : "2de9a0c3-4b21-407c-83d1-031ea0735eb2",
                    "created" : "2019-08-26T10:47:15",
                    "updated" : "2019-08-26T10:47:22",
                    "source" : "central",
                    "productName" : "Burger",
                    "quantity" : 1,
                    "price" : "13.99",
                    "productId" : "burger1",
                    "product" : {
                        "id" : "burger1",
                        "kind" : "product",
                        "quantity" : 1,
                        "price" : "13.99",
                        "literals":{
                        "name" : "Burger"
                        },
                        "img" : "http://placekitten.com/200/300",
                    },
                    "productConfig" : {},
                    "status" : "NEW",
                    "discounts" : [],
                    "extra" : {}
                }
            ],
            "queuePos" : 3,
            "extra" : {}
        }
    ],
    "payments" : [ 
        {
            "id" : "100e0b17-bb15-4a3d-aa29-68da05c49677",
            "source" : "WEB",
            "amount" : "13.99",
            "timestamp" : "2019-08-26T10:47:22",
            "extra" : {}
        }
    ],
    "extra" : {}
  }
}

In your implementation you can retrieve user contact data from users attribute and send an e-mail or text/sms message. By parsing basket/orders you can generate preview of an order details. Sample implementation is here:

CompleteOrderEventCommand

Event is risen up when order is marked as done in the kitchen on KDS screen. It means that order is ready and can be taken by user or is ready to be delivered by driver. This wehbook is requested in the same way (POST) and with the same data as CompleteOrderEventCommand.

Securing your webhook

To protect your webhook from unauthorized requests we strongly recommend to use signature validation. Signature is calculated as a sha256 hash from request body and secure token. You should set this token as a tenant property under a key webhookSecurityToken. Signature is added to each reqeust in the header x-signature. In your webhook implementation you should calculate signature of the incoming request and compare it to the received value from header. If it is not the same, then you should reject such request.

Example implementation

You can find example webhook implementation here: https://github.com/orderingstack/notification-webhook-example .