如何在创建订单后检索客户电子邮件 - Laravel和Shopify

When i create an order, my web-hook returns a response to my controller and below is how i retrieve the details of the order

Controller

public function getOrderDetails()
{
         // get the content of request body    
            $order = $request->getContent();   
            $order = json_decode($order, true);    
            $order_id = $order['number'];                 
            $order_total = $order['total_price'];

            $customer_email = $order['customer.email'];


}

As in my controller, i am able to retrieve the order_id, order_total but i am not able to get the email of the customer who placed the order.

What is wrong in my code ?

This is how the response looks like from Shopify

Response

{
  "id": 820982911946154508,
  "email": "jon@doe.ca",
  "closed_at": null,
  "created_at": "2018-10-26T13:55:26-04:00",
  "updated_at": "2018-10-26T13:55:26-04:00",
  "number": 234,
  "note": null,
 "customer": {
    "id": 115310627314723954,
    "email": "john@test.com",
    "accepts_marketing": false,
    "created_at": null,
 }
}

You can use:

$customer_email = $order['customer']['email'];

1) Your json data has an error. You should remove comma(,) before }

2) Below code works correctly

$order='{
    "id": 820982911946154508,
    "email": "jon@doe.ca",
    "closed_at": null,
    "created_at": "2018-10-26T13:55:26-04:00",
    "updated_at": "2018-10-26T13:55:26-04:00",
    "number": 234,
    "note": null,
    "customer": {
        "id": 115310627314723954,
        "email": "john@test.com",
        "accepts_marketing": false,
        "created_at": null
    }
}';

// get the content of request body
$order = json_decode($order, true);
$order_id = $order['number'];
$order_total = $order['total_price'];

$customer_email = $order['customer']['email'];
echo $customer_email;