Skip to content

Commit

Permalink
Add handler for SHOP_UPDATED webhook
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiasdierich committed Dec 19, 2023
1 parent 5c68522 commit 87b2ba8
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1 deletion.
15 changes: 15 additions & 0 deletions src/Events/ShopifyShopUpdated.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace Codelayer\LaravelShopifyIntegration\Events;

use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

class ShopifyShopUpdated
{
use Dispatchable, SerializesModels;

public function __construct(public string $shop)
{
}
}
2 changes: 2 additions & 0 deletions src/LaravelShopifyIntegrationServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Codelayer\LaravelShopifyIntegration;

use Codelayer\LaravelShopifyIntegration\Events\ShopifyAppInstalled;
use Codelayer\LaravelShopifyIntegration\Events\ShopifyShopUpdated;
use Codelayer\LaravelShopifyIntegration\Http\Middleware\EnsureShopifyInstalled;
use Codelayer\LaravelShopifyIntegration\Http\Middleware\EnsureShopifySession;
use Codelayer\LaravelShopifyIntegration\Lib\DbSessionStorage;
Expand Down Expand Up @@ -45,6 +46,7 @@ public function configurePackage(Package $package): void
private function configurePackageEvents(): void
{
Event::listen(ShopifyAppInstalled::class, RefreshShopDevelopmentState::class);
Event::listen(ShopifyShopUpdated::class, RefreshShopDevelopmentState::class);
}

/**
Expand Down
14 changes: 14 additions & 0 deletions src/Lib/Handlers/ShopUpdated.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Codelayer\LaravelShopifyIntegration\Lib\Handlers;

use Codelayer\LaravelShopifyIntegration\Events\ShopifyShopUpdated;
use Shopify\Webhooks\Handler;

class ShopUpdated implements Handler
{
public function handle(string $topic, string $shop, array $body): void
{
event(new ShopifyShopUpdated($shop));
}
}
3 changes: 2 additions & 1 deletion src/Listeners/RefreshShopDevelopmentState.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Codelayer\LaravelShopifyIntegration\Listeners;

use Codelayer\LaravelShopifyIntegration\Events\ShopifyAppInstalled;
use Codelayer\LaravelShopifyIntegration\Events\ShopifyShopUpdated;
use Codelayer\LaravelShopifyIntegration\Lib\ShopifyDevelopmentShopHandler;
use Codelayer\LaravelShopifyIntegration\Lib\ShopifySessionHandler;
use Codelayer\LaravelShopifyIntegration\Models\ShopifySession;
Expand All @@ -18,7 +19,7 @@ public function __construct(
/**
* Handle the given event.
*/
public function handle(ShopifyAppInstalled $event): void
public function handle(ShopifyAppInstalled|ShopifyShopUpdated $event): void
{
$session = $this->sessionHandler->getSessionForShopOrThrow($event->shop);
$dbSession = ShopifySession::where('session_id', $session->getId())->firstOrFail();
Expand Down

0 comments on commit 87b2ba8

Please sign in to comment.