From ae95665ab930aba095fb14a266996b7c8d68797a Mon Sep 17 00:00:00 2001 From: JP Foster Date: Mon, 4 Nov 2019 17:50:42 +0000 Subject: [PATCH] webhook for handling delivery endpoint --- dummy_webhook_call.sh | 76 +++++++++++++++++++++++++++++++++++++++++++ hooks.json | 47 ++++++++++++++++++++++++++ process_webhook.sh | 7 ++++ 3 files changed, 130 insertions(+) create mode 100755 dummy_webhook_call.sh create mode 100644 hooks.json create mode 100755 process_webhook.sh diff --git a/dummy_webhook_call.sh b/dummy_webhook_call.sh new file mode 100755 index 0000000..4e1c25f --- /dev/null +++ b/dummy_webhook_call.sh @@ -0,0 +1,76 @@ +curl -v --location --request POST "http://05ed6262.ngrok.io/hooks/delivery-test-webhack" \ + --header "Content-Type: application/json" \ + --data "{ + + \"_id\": \"5c6d830a0182d6000e******\", + \"_created\": \"2019-02-20T16:40:44.000000Z\", + \"_updated\": \"2019-02-20T16:40:52.000000Z\", + \"channelOrderId\": \"******-1527\", + \"channelOrderDisplayId\": \"1527\", + \"posLocationId\": \"30458\", + \"location\": \"5bf02f38c6489f002c******\", + \"channelLink\": \"5bf02f38c6489f002c******\", + \"status\": 1, + \"statusHistory\": [ + { + \"_created\": \"2019-02-20T16:40:42.703000Z\", + \"response\": \"\", + \"timeStamp\": \"2019-02-20T16:40:42.703000Z\", + \"status\": 4 + }, + { + \"_created\": \"2019-02-20T16:40:42.726000Z\", + \"response\": \"\", + \"timeStamp\": \"2019-02-20T16:40:42.726000Z\", + \"status\": 1 + } + ], + \"by\": \"\", + \"orderType\": 2, + \"channel\": 2, + \"pickupTime\": \"2019-02-20T16:40:42.000000Z\", + \"deliveryIsAsap\": false, + \"courier\": \" \", + \"customer\": { + + }, + \"deliveryAddress\": { + \"street\": \"\", + \"streetNumber\": \"\", + \"postalCode\": \"\", + \"city\": \"\", + \"extraAddressInfo\": \"\" + }, + \"orderIsAlreadyPaid\": true, + \"payment\": { + \"amount\": 400, + \"type\": 0 + }, + \"note\": \"\", + \"items\": [ + { + \"plu\": \"P1\", + \"name\": \"Product 1\", + \"price\": 200, + \"quantity\": 1, + \"productType\": 1, + \"subItems\": [] + }, + { + \"plu\": \"P2\", + \"name\": \"Product 2\", + \"price\": 200, + \"quantity\": 1, + \"productType\": 1, + \"subItems\": [] + } + ], + \"decimalDigits\": 2, + \"numberOfCustomers\": 1, + \"deliveryCost\": 0, + \"serviceCharge\": 0, + \"discountTotal\": 0, + \"posCustomerId\": \"256706\", + \"account\": \"5be9c971c6489f0029******\", + \"posReceiptId\": \"297812\" +}" diff --git a/hooks.json b/hooks.json new file mode 100644 index 0000000..645d716 --- /dev/null +++ b/hooks.json @@ -0,0 +1,47 @@ +[ + { + "id": "uname", + "execute-command": "uname", + "command-working-directory": "/tmp", + "response-message": "I got the payload!", + "include-command-output-in-response": true, + "response-headers": + [ + { + "name": "Access-Control-Allow-Origin", + "value": "*" + } + ], + "pass-arguments-to-command": + [ + { + "source": "query", + "name": "args" + } + ], + }, + { + "id": "delivery-test-webhack", + "execute-command": "/Users/john-paul.foster/go/src/github.com/iZettle/webhook/process_webhook.sh", + "command-working-directory": "/tmp", + "success-http-response-code": 200, + "include-command-output-in-response": true, + "pass-arguments-to-command": + [ + { + "source": "entire-payload", + } + ], + "response-headers": + [ + { + "name": "Access-Control-Allow-Origin", + "value": "*" + }, + { + "name": "Content-Type", + "value": "application/json" + } + ], + } +] diff --git a/process_webhook.sh b/process_webhook.sh new file mode 100755 index 0000000..1f310ac --- /dev/null +++ b/process_webhook.sh @@ -0,0 +1,7 @@ +#!/bin/sh + +tmpfile=`mktemp order.XXXXXXXX` + +echo $1 > $tmpfile + +echo "{\"posOrderId\":\""`uuidgen`\""}"