简体   繁体   English

如何从Webhook响应中获取Order_ID-Shopify和Laravel

[英]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.

相关问题 如何获取从Shopify Webhook删除的订单ID-Laravel和Shopify - How To Get ID of Order Deleted from Shopify Webhook - Laravel & Shopify 如何从woocommerce中的order_id获取post_id - How to get post_id from order_id in woocommerce Shopify结帐Webhook-如何在shopify结帐Webhook响应中获取客户的电子邮件ID? - Shopify checkout webhook - How to get customer email id in shopify checkout webhook response? 新订单挂钩功能无法从order_id获取商品详情 - Can not get the product details from order_id on the new order hook function 获取order_id,其中order_id具有两个时间x值 - Get order_id where order_id has two time x value 如何在laravel中执行两个where条件,其中order_id相同但product_ids在数组中 - How to execute two where conditions in laravel where order_id is same but product_ids are in array 无法从弹出框中的多个order_id中传递特定的order_id - not able to pass particular order_id from multiple order_id in pop box 在ubercart中,如何在创建用户并将其与order关联后获取uid和order_id - In ubercart how to get uid and order_id after the user is created and associated to order 谢谢页面上的Woocommerce将类别分类为order_id - Woocommerce on Thank You Page get category to order_id 从api返回一个值,用于多个order_id - return a value from api for multiple order_id
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM