How to catch the HTTP POST request sent by a Shopify Webhook

前端 未结 5 662
时光取名叫无心
时光取名叫无心 2021-01-31 05:50

I\'m somewhat of a noob, and not afraid to admit that, I\'m working on this project as a learning experience to get better with php and serverside script/ing handling.

I

5条回答
  •  我在风中等你
    2021-01-31 06:26

    Sorry, I don't have enough reputation to post comments, but here is the contents of the dead link from Edward Ocampo-Gooding's answer:

    PHP Example w/ SimpleXML (PHP 5+)

    The script below shows you how to get the XML data in from Shopify into your script, archive the file, and send the proper headers ...

    Given that the new order subscription setup in the admin for the webhook is: http://example.com/some-script.php?key=123456789

    Contents of some-script.php on http://example.com/:

    {'billing-address'}->name);
    $email = trim($xml->email);
    
    // Create productTitles array with titles from products
    foreach ($xml->{'line-items'}->{'line-item'} as $lineItem) {
      array_push($productTitles, trim($lineItem->title));
    }
    
    // You would then go on using $name, $email, $productTitles in your script
    // to do whatever the heck you please ...
    
    // Once you are done doing what you need to do, let Shopify know you have 
    // the data and all is well!
    header('HTTP/1.0 200 OK');
    exit();
    
    // If you want to tell Shopify to try sending the data again, i.e. something
    // failed with your processing and you want to try again later
    header('HTTP/1.0 400 Bad request');
    exit();
    ?>
    

提交回复
热议问题