简体   繁体   中英

Not receiving notifications from webhook - laravel & shopify

I am creating an app for merchants and Shopify using laravel. I have configured and installed webhooks to send admins notifications when new customers are created in config/shopify.php in my app.

shopify.php

use Oseintow\Shopify\Facades\Shopify;
use Laravel\Socialite\Facades\Socialite;
use App\User;
use App\Store;
use App\UserProvider;
use Auth;

    $shopifyUser = Socialite::driver('shopify')->stateless()->user();
    $shopUrl = $shopifyUser->nickname;
    $accessToken = $shopifyUser->token;

    Shopify::setShopUrl($shopUrl)->setAccessToken($accessToken)->post("admin/webhooks.json",
     [
        'webhook' => 
        ['topic' => 'customers/create',
        'address' => 'https://shopify.kast.com/webhook',
        'format' => 'json'
        ]
    ]);

Route

Route::post('/webhook', 'ReceiverController@webhook');

ReceiverController

 public function webhook()
    {
       send sms/email to admin
    }

Now when I configure the webhook in the shop admin settings and send a test notification or create a customer, I receive the SMS/emails

But when I delete the webhook settings from the admin page and create a new customer for the shop, I don't receive the SMS.

Is there any error in shopify.php (webhook configuration) for my app?

PS: shop domain is founz.myshopify.com and app is hosted https://shopify.kast.com

Most probably you didn't register a webhook using access token.

If you're using Oseintow\\Shopify , your shopify.php file should look like:

<?php

return [        
    'key' => env("SHOPIFY_APIKEY", '0f20e4692981aefb8558etrgrh72thty5'),
    'secret' => env("SHOPIFY_SECRET", 'fgghg55666585f1a09214drtg56454g')
]; 

Let it just holds your public app's credentials.

It looks like you haven't registered any webhook using access token. When you register a webhook using shopify admin, that webhook will be fired to all application. Don't do that unless you know what you're doing.

Instead try registering the same webhook using Postman with your access token and see if it is working. And then use your programming skills to automate it. Cheers!

There Can be two main reason for that.

1) Webhook could not created successfully. to check this Please make API call with GET Request

GET /admin/api/2019-10/webhooks.json

If you did not get your desired webhook in the response please create it

2) In Laravel spacific development,you need to bypass VerifyCsrfToken middle-ware for your webhook route as Laravel will not allow & blocks cross site requests default.to do so please follow below steps.

Go to app/http/middleware/VerifyCsrfToken & add your route in the $except array.

As Example :

protected $except = [
  '/app/uninstalled-webhook-shopify/*',
  '/products/create-webhook-shopify/*',
];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM