Skip to content

Commit 87b2ba8

Browse files
committed
Add handler for SHOP_UPDATED webhook
1 parent 5c68522 commit 87b2ba8

File tree

4 files changed

+33
-1
lines changed

4 files changed

+33
-1
lines changed

src/Events/ShopifyShopUpdated.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace Codelayer\LaravelShopifyIntegration\Events;
4+
5+
use Illuminate\Foundation\Events\Dispatchable;
6+
use Illuminate\Queue\SerializesModels;
7+
8+
class ShopifyShopUpdated
9+
{
10+
use Dispatchable, SerializesModels;
11+
12+
public function __construct(public string $shop)
13+
{
14+
}
15+
}

src/LaravelShopifyIntegrationServiceProvider.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Codelayer\LaravelShopifyIntegration;
44

55
use Codelayer\LaravelShopifyIntegration\Events\ShopifyAppInstalled;
6+
use Codelayer\LaravelShopifyIntegration\Events\ShopifyShopUpdated;
67
use Codelayer\LaravelShopifyIntegration\Http\Middleware\EnsureShopifyInstalled;
78
use Codelayer\LaravelShopifyIntegration\Http\Middleware\EnsureShopifySession;
89
use Codelayer\LaravelShopifyIntegration\Lib\DbSessionStorage;
@@ -45,6 +46,7 @@ public function configurePackage(Package $package): void
4546
private function configurePackageEvents(): void
4647
{
4748
Event::listen(ShopifyAppInstalled::class, RefreshShopDevelopmentState::class);
49+
Event::listen(ShopifyShopUpdated::class, RefreshShopDevelopmentState::class);
4850
}
4951

5052
/**

src/Lib/Handlers/ShopUpdated.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
namespace Codelayer\LaravelShopifyIntegration\Lib\Handlers;
4+
5+
use Codelayer\LaravelShopifyIntegration\Events\ShopifyShopUpdated;
6+
use Shopify\Webhooks\Handler;
7+
8+
class ShopUpdated implements Handler
9+
{
10+
public function handle(string $topic, string $shop, array $body): void
11+
{
12+
event(new ShopifyShopUpdated($shop));
13+
}
14+
}

src/Listeners/RefreshShopDevelopmentState.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Codelayer\LaravelShopifyIntegration\Listeners;
44

55
use Codelayer\LaravelShopifyIntegration\Events\ShopifyAppInstalled;
6+
use Codelayer\LaravelShopifyIntegration\Events\ShopifyShopUpdated;
67
use Codelayer\LaravelShopifyIntegration\Lib\ShopifyDevelopmentShopHandler;
78
use Codelayer\LaravelShopifyIntegration\Lib\ShopifySessionHandler;
89
use Codelayer\LaravelShopifyIntegration\Models\ShopifySession;
@@ -18,7 +19,7 @@ public function __construct(
1819
/**
1920
* Handle the given event.
2021
*/
21-
public function handle(ShopifyAppInstalled $event): void
22+
public function handle(ShopifyAppInstalled|ShopifyShopUpdated $event): void
2223
{
2324
$session = $this->sessionHandler->getSessionForShopOrThrow($event->shop);
2425
$dbSession = ShopifySession::where('session_id', $session->getId())->firstOrFail();

0 commit comments

Comments
 (0)