Skip to content

Commit

Permalink
Added webhook endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
loevgaard committed Jun 6, 2024
1 parent d4bf40b commit 8b642f2
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/Client/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
use Psr\Log\NullLogger;
use Setono\PeakWMS\Client\Endpoint\SalesOrderEndpoint;
use Setono\PeakWMS\Client\Endpoint\SalesOrderEndpointInterface;
use Setono\PeakWMS\Client\Endpoint\WebhookEndpoint;
use Setono\PeakWMS\Client\Endpoint\WebhookEndpointInterface;
use Setono\PeakWMS\Exception\InternalServerErrorException;
use Setono\PeakWMS\Exception\NotAuthorizedException;
use Setono\PeakWMS\Exception\NotFoundException;
Expand All @@ -33,6 +35,8 @@ final class Client implements ClientInterface, LoggerAwareInterface

private ?SalesOrderEndpointInterface $salesOrderEndpoint = null;

private ?WebhookEndpointInterface $webhookEndpoint = null;

private ?HttpClientInterface $httpClient = null;

private ?RequestFactoryInterface $requestFactory = null;
Expand Down Expand Up @@ -130,6 +134,16 @@ public function salesOrder(): SalesOrderEndpointInterface
return $this->salesOrderEndpoint;
}

public function webhook(): WebhookEndpointInterface
{
if (null === $this->webhookEndpoint) {
$this->webhookEndpoint = new WebhookEndpoint($this, $this->getMapperBuilder(), 'webhook');
$this->webhookEndpoint->setLogger($this->logger);
}

return $this->webhookEndpoint;
}

public function setMapperBuilder(MapperBuilder $mapperBuilder): void
{
$this->mapperBuilder = $mapperBuilder;
Expand Down
3 changes: 3 additions & 0 deletions src/Client/ClientInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Setono\PeakWMS\Client\Endpoint\SalesOrderEndpointInterface;
use Setono\PeakWMS\Client\Endpoint\WebhookEndpointInterface;
use Setono\PeakWMS\Exception\InternalServerErrorException;
use Setono\PeakWMS\Exception\NotFoundException;
use Setono\PeakWMS\Exception\UnexpectedStatusCodeException;
Expand Down Expand Up @@ -48,4 +49,6 @@ public function post(string $uri, array|object $body): ResponseInterface;
public function delete(string $uri, int $id): ResponseInterface;

public function salesOrder(): SalesOrderEndpointInterface;

public function webhook(): WebhookEndpointInterface;
}
25 changes: 25 additions & 0 deletions src/Client/Endpoint/WebhookEndpoint.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

namespace Setono\PeakWMS\Client\Endpoint;

use Setono\PeakWMS\DataTransferObject\Webhook\Webhook;

/**
* @extends Endpoint<Webhook>
*/
final class WebhookEndpoint extends Endpoint implements WebhookEndpointInterface
{
/**
* @use CreatableEndpointTrait<Webhook>
*/
use CreatableEndpointTrait;

use DeletableEndpointTrait;

protected static function getDataClass(): string
{
return Webhook::class;
}
}
15 changes: 15 additions & 0 deletions src/Client/Endpoint/WebhookEndpointInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

namespace Setono\PeakWMS\Client\Endpoint;

use Setono\PeakWMS\DataTransferObject\Webhook\Webhook;

/**
* @extends EndpointInterface<Webhook>
* @extends CreatableEndpointInterface<Webhook>
*/
interface WebhookEndpointInterface extends EndpointInterface, CreatableEndpointInterface, DeletableEndpointInterface
{
}
20 changes: 20 additions & 0 deletions src/DataTransferObject/Webhook/Name.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

namespace Setono\PeakWMS\DataTransferObject\Webhook;

enum Name: int
{
case StockAdjust = 100;
case EanUpdates = 101;
case PickOrderPacked = 102;
case InboundOrderClosed = 103;
case OrderRefunded = 104;
case ProductCreateUpdate = 105;
case FulfillmentNotPossible = 106;
case InboundDeliveryClosed = 107;
case OrderSendAgain = 108;
case OrderStateChanged = 109;
case PickOrderFullyPacked = 110;
}
20 changes: 20 additions & 0 deletions src/DataTransferObject/Webhook/Webhook.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

namespace Setono\PeakWMS\DataTransferObject\Webhook;

use Setono\PeakWMS\DataTransferObject\AbstractDataTransferObject;

/**
* See https://api.peakwms.com/api/documentation/index.html#model-WebhookDto
*/
final class Webhook extends AbstractDataTransferObject
{
public function __construct(
public Name $name,
public string $url,
public ?int $id = null,
) {
}
}

0 comments on commit 8b642f2

Please sign in to comment.