如何安装客户/创建Webhook shopify-Laravel

时间:2018-10-17 16:21:24

标签: php laravel

我正在安装一个Webhook,当他们添加新的administrators时会通知customers

文档在Ruby中,但是我正在laravel中尝试这样做。

这就是我所做的:

  1. 我创建了工作CustomerInstallShopifyWebhook
  2. 我在web.php中添加了该地址的路线

现在,当我添加customer时,仍然没有收到通知。

我的工作分配正确了吗?

CustomerInstallShopifyWebhook

class CustomerInstallShopifyWebhook implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    public $domain;  
    public $token;
    public $store;

    public function __construct($domain, $token, \App\Store $store)
    {
    $this->domain = $domain;
    $this->token = $token;
    $this->store = $store;
    }

    public function handle()
    {
        //
       $shopify = \Shopify::retrieve($this->domain, $this->token);
       $customerCreate = array
         (
      'webhook'=>array
       (
        'topic'=> 'customers/create',
        'address'=> 'https://shopify.com/webhook/shopify/customer-created',
        'format'=> 'json'
       )
       );

     $customerCreate_webhook = $sc->call('POST', '/admin/webhooks.json', $customerCreate);

     header('Content-type: application/json');
     echo json_encode(array("state"=>"success", "customer_create"=>$customerCreate_webhook));

    }
}

路线

Route::post('webhook/shopify/customer-created', function(\Illuminate\Http\Request $request) {
        $query = "?key=**********&to=0501149794&msg=Testing Shopify App&sender_id=Shopify";
        $final_uri = $baseurl.$query;
        $response = file_get_contents($final_uri);
        header ("Content-Type:text/xml");
})->middleware('webhook');

0 个答案:

没有答案