Webhooks
Configure webhooks to notify your application, whenever a something happens in Shopify.
You can setup webhooks by registering the route in the RouteServiceProvider
just below the route groups that pull in the routes/api
and routes/web
files:
$this->routes(function () {
// ...
Route::shopifyWebhooks();
});
This gives you a new endpoint in your application: shopify/webhooks
. All webhooks sent to this endpoint will trigger an event, which you can listen to in your EventServiceProvider
:
protected $listen = [
'shopify-webhooks.orders-create' => [
CreateOrderFromWebhook::class,
],
];
All events use the following convention:
public function eventName(): string
{
return 'shopify-webhooks.'.str_replace('/', '-', $this->topic());
}
The listener might look like this:
use Illuminate\Contracts\Queue\ShouldQueue;
use Pactode\Shopify\Webhooks\Webhook;
class CreateOrderFromWebhook implements ShouldQueue
{
public function handle(Webhook $webhook)
{
$webhook->domain(); // your-shop.myshopify.com
$webhook->topic(); // orders/create
$webhook->payload(); // the payload of the webhook event
}
}
In terms of verifying webhooks it happens automatically. It retrieves the webhook secret from the config by default, but you can define your own SecretProvider
and replace the one in config/shopify
in case you want to retrieve it from the database or somewhere else.
Please use the webhook secret from Settings > Notifications
in Shopify admin. You have to create the webhook before it creates the secret.
Last updated