【问题标题】:How To Get Order_ID From Webhook Response - Shopify & Laravel如何从 Webhook 响应中获取 Order_ID - Shopify & Laravel
【发布时间】:2018-10-31 09:48:59
【问题描述】:

我已经在我的 shopify 应用中注册了我的 webhook,并且我能够从 webhook 接收到我指定地址的响应。

但是我现在想做的是,当我创建一个订单并将响应发送到指定地址时,我怎么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'
             ]
            ]);
    }

网络

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

【问题讨论】:

    标签: php laravel shopify


    【解决方案1】:
    // 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'];
    

    【讨论】:

    • 如果你能解释一下就好了
    • 是的,刚刚添加了 cmets :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-18
    • 2015-03-28
    • 2021-05-18
    • 2018-07-23
    相关资源
    最近更新 更多