[英]How To Get Order_ID From Webhook Response - Shopify & Laravel
I have registered my webhooks in my shopify app and i am able to receive responses from the webhook to my specified address. 我已经在shopify应用程序中注册了Webhooks,并且能够收到来自Webhook到我指定地址的回复。
But what i want to do now is, when i create an order and the response is sent to the specified address, how can i get the ID of the order created
? 但是我现在要做的是,当我创建订单并将响应发送到指定的地址时,如何
get the ID of the order created
?
I want to include the order id
in the notification sent to the customer? 我想在发送给客户的通知中包含
order id
吗?
PS: I am new to laravel and creating apps in shopify. PS:我对laravel和在shopify中创建应用程序不熟悉。
Controller 控制者
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');
// 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'];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.