-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
110 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
namespace BigCommerce\ApiV3\Api\Webhooks; | ||
|
||
use BigCommerce\ApiV3\Api\Generic\GetAllResources; | ||
use BigCommerce\ApiV3\Api\Generic\V3ApiBase; | ||
use BigCommerce\ApiV3\ResponseModels\Webhook\WebhookEventsResponse; | ||
|
||
class WebhookEventsApi extends V3ApiBase | ||
{ | ||
use GetAllResources; | ||
|
||
public const EVENTS_ENDPOINT = 'hooks/events'; | ||
|
||
public function multipleResourceUrl(): string | ||
{ | ||
return self::EVENTS_ENDPOINT; | ||
} | ||
|
||
/** | ||
* Get a list of events that were sent but not successfully received. Events are stored for not less than one week | ||
*/ | ||
public function getAll(array $filters = [], int $page = 1, int $limit = 250): WebhookEventsResponse | ||
{ | ||
return new WebhookEventsResponse($this->getAllResources($filters, $page, $limit)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
namespace BigCommerce\ApiV3\ResourceModels\Webhook; | ||
|
||
use BigCommerce\ApiV3\ResourceModels\ResourceModel; | ||
|
||
class WebhookEvent extends ResourceModel | ||
{ | ||
public string $scope; | ||
public string $store_id; | ||
public object $data; | ||
public string $hash; | ||
public string $created_at; | ||
public string $producer; | ||
} |
22 changes: 22 additions & 0 deletions
22
src/BigCommerce/ResponseModels/Webhook/WebhookEventsResponse.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
namespace BigCommerce\ApiV3\ResponseModels\Webhook; | ||
|
||
use BigCommerce\ApiV3\ResourceModels\Webhook\WebhookEvent; | ||
use BigCommerce\ApiV3\ResponseModels\PaginatedResponse; | ||
|
||
class WebhookEventsResponse extends PaginatedResponse | ||
{ | ||
/** | ||
* @return WebhookEvent[] | ||
*/ | ||
public function getEvents(): array | ||
{ | ||
return $this->getData(); | ||
} | ||
|
||
protected function resourceClass(): string | ||
{ | ||
return WebhookEvent::class; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
namespace BigCommerce\Tests\Api\Webhooks; | ||
|
||
use BigCommerce\Tests\BigCommerceApiTest; | ||
|
||
class WebhookEventsApiTest extends BigCommerceApiTest | ||
{ | ||
public function testCanGetAllEvents() | ||
{ | ||
$this->setReturnData('webhooks__events__get_all.json'); | ||
$events = $this->getApi()->webhooks()->events()->getAll()->getEvents(); | ||
|
||
$this->assertEquals('store/sku/inventory/updated', $events[0]->scope); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
tests/BigCommerce/responses/webhooks__events__get_all.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"data": [ | ||
{ | ||
"scope": "store/sku/inventory/updated", | ||
"store_id": "25967773", | ||
"data": { | ||
"product": "new", | ||
"stock": 123 | ||
}, | ||
"hash": "0c20013b66c630f5c7473eef26bd71089bb461b4", | ||
"created_at": 1680144702, | ||
"producer": "stores/xxbwhvt3gd" | ||
} | ||
], | ||
"meta": { | ||
"pagination": { | ||
"total": 1, | ||
"count": 1, | ||
"per_page": 250, | ||
"current_page": 1, | ||
"total_pages": 1 | ||
} | ||
} | ||
} |