Hi, currently I'm using 3rd party API for my laravel application. It will send a webhook to the url I provide for them. And the webhook is in json format.
My question is how to retrieve it in function and store it to database? because there's no documentation about how to do that.
And after searching in google I created a function to do it, and the code is like this (not working):
public function webhook_resi()
{
$response = file_get_contents('php://input');
$data = json_decode($response->getBody());
if($data->status == 'ON_PROCESS') {
$status = 'on_delivery';
} elseif($data->status == 'DELIVERED') {
$status = 'delivered';
}
$order = Order::where('code', $response->external_id)->update([
'delivery_status' => $status
]);
$order_detail = OrderDetail::where('order_id', $order->id)->update([
'delivery_status' => $status
]);
}
And the webhook sended to my url is like this:
{
"result": {
"status": "ON PROCESS",
"summary": {
"awb": "150450014862419",
"courier": "jne",
"service": "REG19",
"date": "2019-06-18 16:49:00",
"desc": "SEPATU ",
"amount": "43000",
"weight": "1"
},
"detail": {
"origin": "BATAM",
"destination": "KUNINGAN, KAB KUNINGAN",
"shipper": "03ALINA",
"receiver": "DIAN RATNA KHRISTIAN "
},
"history": [
{
"date": "2019-06-18 16:49:00",
"desc": "Shipment Received By Jne Counter Officer At [batam]",
"location": "BATAM"
},
{
"date": "2019-06-18 21:02:00",
"desc": "Shipment Picked Up By Jne Courier [batam]",
"location": "BATAM"
},
{
"date": "2019-06-18 21:42:00",
"desc": "Received At Sorting Center [batam]",
"location": "BATAM"
},
{
"date": "2019-06-19 00:40:00",
"desc": "Processed At Sorting Center [batam]",
"location": "BATAM"
}
]
},
"external_id": "o-123-2019"
}
This is my first time using webhook, so I don't have any idea how to do it. Sorry and thank you