Skip to content
This repository has been archived by the owner on Nov 30, 2022. It is now read-only.

Add webhookId to Webhooks #1066

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
composer.lock
.php-cs-fixer.cache
.phpunit.result.cache
.idea
12 changes: 12 additions & 0 deletions src/Contracts/Objects/Values/WebhookId.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace Osiset\ShopifyApp\Contracts\Objects\Values;

use Funeralzone\ValueObjects\ValueObject;

/**
* Webhook ID's value object.
*/
interface WebhookId extends ValueObject
{
}
22 changes: 22 additions & 0 deletions src/Contracts/WebhookJob.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace Osiset\ShopifyApp\Contracts;

use Illuminate\Contracts\Queue\ShouldQueue;
use Osiset\ShopifyApp\Contracts\Objects\Values\WebhookId;
use Osiset\ShopifyApp\Objects\Values\ShopDomain;
use stdClass;

interface WebhookJob extends ShouldQueue
{
/**
* Create a new job instance.
*
* @param ShopDomain|string $shopId The shop Domain.
* @param WebhookId|string $webhookId The webhooks ID.
* @param stdClass $data The webhook payload.
*
* @return void
*/
public function __construct(string $shopId, string $webhookId, stdClass $data);
}
23 changes: 16 additions & 7 deletions src/Messaging/Jobs/AppUninstalledJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,17 @@
use Illuminate\Queue\SerializesModels;
use Osiset\ShopifyApp\Actions\CancelCurrentPlan;
use Osiset\ShopifyApp\Contracts\Commands\Shop as IShopCommand;
use Osiset\ShopifyApp\Contracts\Objects\Values\WebhookId;
use Osiset\ShopifyApp\Contracts\Queries\Shop as IShopQuery;
use Osiset\ShopifyApp\Contracts\WebhookJob;
use Osiset\ShopifyApp\Objects\Values\ShopDomain;
use Osiset\ShopifyApp\Util;
use stdClass;

/**
* Webhook job responsible for handling when the app is uninstalled.
*/
class AppUninstalledJob implements ShouldQueue
class AppUninstalledJob implements WebhookJob
{
use Dispatchable;
use InteractsWithQueue;
Expand All @@ -30,26 +32,33 @@ class AppUninstalledJob implements ShouldQueue
* @var ShopDomain|string
*/
protected $domain;

/**
* The webhook data.
*
* @var object
*/
protected $data;
/**
* The webhook id
*
* @var WebhookId|string
*/
protected $webhookId;

/**
* Create a new job instance.
*
* @param string $domain The shop domain.
* @param stdClass $data The webhook data (JSON decoded).
* @param ShopDomain|string $shopId The shop Domain.
* @param WebhookId|string $webhookId The webhooks ID.
* @param stdClass $data The webhook data (JSON decoded).
*
* @return void
*/
public function __construct(string $domain, stdClass $data)
public function __construct(string $domain, string $webhookId, stdClass $data)
{
$this->domain = $domain;
$this->data = $data;
$this->webhookId = $webhookId;
}

/**
Expand All @@ -62,8 +71,8 @@ public function __construct(string $domain, stdClass $data)
* @return bool
*/
public function handle(
IShopCommand $shopCommand,
IShopQuery $shopQuery,
IShopCommand $shopCommand,
IShopQuery $shopQuery,
CancelCurrentPlan $cancelCurrentPlanAction
): bool {
// Convert the domain
Expand Down
1 change: 1 addition & 0 deletions src/Traits/WebhookController.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public function handle(string $type, Request $request): ResponseResponse

$jobClass::dispatch(
$request->header('x-shopify-shop-domain'),
$request->header('x-shopify-webhook-id'),
$jobData
)->onQueue(Util::getShopifyConfig('job_queues')['webhooks']);

Expand Down