-
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
9 changed files
with
183 additions
and
2 deletions.
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,41 @@ | ||
<?php | ||
|
||
namespace BigCommerce\ApiV3\Api\Webhooks; | ||
|
||
use BigCommerce\ApiV3\Api\Generic\GetResource; | ||
use BigCommerce\ApiV3\Api\Generic\V3ApiBase; | ||
use BigCommerce\ApiV3\ResponseModels\Webhook\AdminInfoResponse; | ||
use GuzzleHttp\RequestOptions; | ||
|
||
class WebhookAdminApi extends V3ApiBase | ||
{ | ||
use GetResource; | ||
|
||
public const WEBHOOK_ADMIN_ENDPOINT = 'hooks/admin'; | ||
|
||
public function singleResourceUrl(): string | ||
{ | ||
return self::WEBHOOK_ADMIN_ENDPOINT; | ||
} | ||
|
||
public function get(?bool $isActive = null): AdminInfoResponse | ||
{ | ||
$filter = is_null($isActive) ? [] : ['is_active' => $isActive]; | ||
return new AdminInfoResponse($this->getResource($filter)); | ||
} | ||
|
||
/** | ||
* Update email addresses that are sent notification emails when any domain associated with the API account | ||
* is denylisted or when a webhook is deactivated. Supports upsert functionality in the case that no email | ||
* address exists yet. | ||
*/ | ||
public function upsertEmails(array $emails): void | ||
{ | ||
$this->getClient()->getRestClient()->put( | ||
$this->singleResourceUrl(), | ||
[ | ||
RequestOptions::JSON => ['emails' => $emails] | ||
] | ||
); | ||
} | ||
} |
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,22 @@ | ||
<?php | ||
|
||
namespace BigCommerce\ApiV3\ResourceModels\Webhook; | ||
|
||
use BigCommerce\ApiV3\ResourceModels\ResourceModel; | ||
|
||
class BlockedDomain extends ResourceModel | ||
{ | ||
public string $destination; | ||
public string $time_left; | ||
|
||
/** | ||
* @var BlockedDomainReason[] | ||
*/ | ||
public array $reasons; | ||
|
||
protected function beforeBuildObject(): void | ||
{ | ||
self::buildObjectArray('reasons', BlockedDomainReason::class); | ||
parent::beforeBuildObject(); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/BigCommerce/ResourceModels/Webhook/BlockedDomainReason.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,12 @@ | ||
<?php | ||
|
||
namespace BigCommerce\ApiV3\ResourceModels\Webhook; | ||
|
||
use BigCommerce\ApiV3\ResourceModels\ResourceModel; | ||
|
||
class BlockedDomainReason extends ResourceModel | ||
{ | ||
public string $failure_description; | ||
public int $count; | ||
public int $timestamp; | ||
} |
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
28 changes: 28 additions & 0 deletions
28
src/BigCommerce/ResourceModels/Webhook/WebhookAdminInfo.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,28 @@ | ||
<?php | ||
|
||
namespace BigCommerce\ApiV3\ResourceModels\Webhook; | ||
|
||
use BigCommerce\ApiV3\ResourceModels\ResourceModel; | ||
|
||
class WebhookAdminInfo extends ResourceModel | ||
{ | ||
/** | ||
* @var string[] | ||
*/ | ||
public array $emails; | ||
/** | ||
* @var Webhook[] | ||
*/ | ||
public array $hooks_list; | ||
/** | ||
* @var BlockedDomain[] | ||
*/ | ||
public array $blocked_domains; | ||
|
||
protected function beforeBuildObject(): void | ||
{ | ||
self::buildObjectArray('hooks_list', Webhook::class); | ||
self::buildObjectArray('blocked_domains', BlockedDomain::class); | ||
parent::beforeBuildObject(); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/BigCommerce/ResponseModels/Webhook/AdminInfoResponse.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\WebhookAdminInfo; | ||
use BigCommerce\ApiV3\ResponseModels\SingleResourceResponse; | ||
use stdClass; | ||
|
||
class AdminInfoResponse extends SingleResourceResponse | ||
{ | ||
private WebhookAdminInfo $adminInfo; | ||
|
||
public function getAdminInfo(): WebhookAdminInfo | ||
{ | ||
return $this->adminInfo; | ||
} | ||
|
||
protected function addData(stdClass $rawData): void | ||
{ | ||
$this->adminInfo = new WebhookAdminInfo($rawData); | ||
} | ||
} |
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 WebhookAdminApiTest extends BigCommerceApiTest | ||
{ | ||
public function testCanGetAdminInfo() | ||
{ | ||
$this->setReturnData('webhooks__admin__get.json'); | ||
$info = $this->getApi()->webhooks()->admin()->get()->getAdminInfo(); | ||
|
||
$this->assertEquals('https://httpstat.us/200', $info->hooks_list[1]->destination); | ||
} | ||
} |
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,35 @@ | ||
{ | ||
"data": { | ||
"emails": [ | ||
"[email protected]" | ||
], | ||
"hooks_list": [ | ||
{ | ||
"id": 25967773, | ||
"client_id": "6qczasxdcbgvjubghnynimwthwr", | ||
"store_hash": "xxabcdt9gd", | ||
"scope": "store/sku/inventory/updated", | ||
"destination": "https://aligent.com.au/test", | ||
"headers": null, | ||
"is_active": true, | ||
"created_at": 1680144702, | ||
"updated_at": 1680144702, | ||
"events_history_enabled": false | ||
}, | ||
{ | ||
"id": 25967774, | ||
"client_id": "6qczasxdcbgvjubghnynimwthwr", | ||
"store_hash": "xxabcdt9gd", | ||
"scope": "store/sku/inventory/updated", | ||
"destination": "https://httpstat.us/200", | ||
"headers": null, | ||
"is_active": true, | ||
"created_at": 1680144907, | ||
"updated_at": 1680144907, | ||
"events_history_enabled": false | ||
} | ||
], | ||
"blocked_domains": [] | ||
}, | ||
"meta": {} | ||
} |