Как получить Order_ID из ответа Webhook - Shopify & Laravel - PullRequest
0 голосов
/ 31 октября 2018

Я зарегистрировал своих веб-крючков в своем приложении shopify и могу получать ответы от веб-крючка на мой указанный адрес.

Но то, что я хочу сделать сейчас, - это когда я создаю заказ и отправляю ответ на указанный адрес, как я могу get the ID of the order created?

Я хочу включить order id в уведомление, отправленное клиенту?

PS: я новичок в laravel и создании приложений в shopify.

Контроллер

  public function orderCreateWebhook(Request $request)
    {              
        //get order_id here and send notification
        notification = "A new order with id [order_id] has been 
                       created";
        SendSMS(notification); 
    }

   public function registerOrderCreateWebhook(Request $request)
    {
            $shop = "example.myshopify.com";
            $token = "xxxxxxxxxxxxxxxxxxxxxx";
            $shopify = Shopify::setShopUrl($shop)->setAccessToken($token);
            Shopify::setShopUrl($shop)->setAccessToken($token)->post("admin/webhooks.json", ['webhook' => 
             ['topic' => 'orders/create',
             'address' => 'https://shop.domain.com/order-create-webhook',
             'format' => 'json'
             ]
            ]);
    }

Web

//register order create
Route::get('/register-order-create-webhook', 'AppController@registerOrderCreateWebhook');  
Route::post('order-create-webhook', 'AppController@orderCreateWebhook');

1 Ответ

0 голосов
/ 31 октября 2018
// get the content of request body    
$order = $request->getContent();

// decode json and covert to array
$order = json_decode($order, true);

// get the 'id' key which is your order id    
$order_id = $order['id'];
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...