diff --git a/CHANGELOG.md b/CHANGELOG.md index a3c0755..de2ca12 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) princip - Add `IdentifyScenarioVersion.restrictedCountries` - Add `EnvelopeTemplateDocumentAssignments` endpoint - Add `Envelope.createdBy` and `Envelope.sentBy` +- Add `BatchSendings` and `BatchSendingsItems` endpoints ## [2.4.0] - 2024-05-14 ### Added diff --git a/src/DigiSign.php b/src/DigiSign.php index 43da060..7f1adff 100644 --- a/src/DigiSign.php +++ b/src/DigiSign.php @@ -9,6 +9,7 @@ use DigitalCz\DigiSign\Auth\Credentials; use DigitalCz\DigiSign\Endpoint\AccountEndpoint; use DigitalCz\DigiSign\Endpoint\AuthEndpoint; +use DigitalCz\DigiSign\Endpoint\BatchSendingsEndpoint; use DigitalCz\DigiSign\Endpoint\DeliveriesEndpoint; use DigitalCz\DigiSign\Endpoint\EndpointInterface; use DigitalCz\DigiSign\Endpoint\EnumsEndpoint; @@ -128,8 +129,8 @@ public function validateSignature(string $payload, string $header, string $secre throw new InvalidSignatureException('Unable to parse signature header'); } - $ts = (int)($matches['t'] ?? 0); - $signature = $matches['s'] ?? ''; + $ts = (int)($matches['t']); + $signature = $matches['s']; if ($ts < time() - $this->signatureTolerance) { throw new InvalidSignatureException("Request is older than {$this->signatureTolerance} seconds"); @@ -243,6 +244,11 @@ public function deliveries(): DeliveriesEndpoint return new DeliveriesEndpoint($this); } + public function batchSendings(): BatchSendingsEndpoint + { + return new BatchSendingsEndpoint($this); + } + public function identifications(): IdentificationsEndpoint { return new IdentificationsEndpoint($this); diff --git a/src/Endpoint/BatchSendingsEndpoint.php b/src/Endpoint/BatchSendingsEndpoint.php new file mode 100644 index 0000000..f325b4d --- /dev/null +++ b/src/Endpoint/BatchSendingsEndpoint.php @@ -0,0 +1,34 @@ + + * @method BatchSending get(string $id) + * @method BatchSending update(string $id, array $body) + * @method BatchSending create(array $body) + */ +final class BatchSendingsEndpoint extends ResourceEndpoint +{ + use GetEndpointTrait; + use UpdateEndpointTrait; + use CreateEndpointTrait; + + public function __construct(DigiSign $parent) + { + parent::__construct($parent, '/api/batch-sendings'); + } + + public function items(string $id): BatchSendingsItemsEndpoint + { + return new BatchSendingsItemsEndpoint($this, $id); + } +} diff --git a/src/Endpoint/BatchSendingsItemsEndpoint.php b/src/Endpoint/BatchSendingsItemsEndpoint.php new file mode 100644 index 0000000..0d9ca54 --- /dev/null +++ b/src/Endpoint/BatchSendingsItemsEndpoint.php @@ -0,0 +1,26 @@ + + */ +final class BatchSendingsItemsEndpoint extends ResourceEndpoint +{ + public function __construct(BatchSendingsEndpoint $parent, string $batchSending) + { + parent::__construct($parent, '/{id}/items', BaseResource::class, ['id' => $batchSending]); + } + + /** + * @param mixed[] $body + */ + public function import(array $body): BaseResource + { + return $this->createResource($this->postRequest('/import', ['json' => $body])); + } +} diff --git a/src/Resource/BaseResource.php b/src/Resource/BaseResource.php index b6c1138..05c0d80 100644 --- a/src/Resource/BaseResource.php +++ b/src/Resource/BaseResource.php @@ -161,7 +161,7 @@ protected function setProperty(string $property, mixed $value): void // parse Resource class from type preg_match('/Collection<(.+)>/', $type, $matches); /** @var class-string $resourceClass */ - $resourceClass = $matches[1]; + $resourceClass = $matches[1] ?? ''; if (!class_exists($resourceClass)) { $reflection = new ReflectionClass($this::class); diff --git a/src/Resource/BatchSending.php b/src/Resource/BatchSending.php new file mode 100644 index 0000000..be966b7 --- /dev/null +++ b/src/Resource/BatchSending.php @@ -0,0 +1,33 @@ + + */ + public array $importFields; +} diff --git a/tests/DigiSignTest.php b/tests/DigiSignTest.php index 4419fd2..05d1508 100644 --- a/tests/DigiSignTest.php +++ b/tests/DigiSignTest.php @@ -134,6 +134,8 @@ public function testChildren(): void self::assertSame('/api/auth-token', $mockClient->getLastRequest()->getUri()->getPath()); $dgs->account()->request('GET'); self::assertSame('/api/account', $mockClient->getLastRequest()->getUri()->getPath()); + $dgs->batchSendings()->request('GET'); + self::assertSame('/api/batch-sendings', $mockClient->getLastRequest()->getUri()->getPath()); $dgs->envelopes()->request('GET'); self::assertSame('/api/envelopes', $mockClient->getLastRequest()->getUri()->getPath()); $dgs->envelopeTemplates()->request('GET'); diff --git a/tests/Endpoint/BatchSendingEndpointTest.php b/tests/Endpoint/BatchSendingEndpointTest.php new file mode 100644 index 0000000..a8537eb --- /dev/null +++ b/tests/Endpoint/BatchSendingEndpointTest.php @@ -0,0 +1,33 @@ +items('foo'), '/api/batch-sendings/foo/items'); + } + + public function testCRUD(): void + { + self::endpoint()->get('foo'); + self::assertLastRequest('GET', "/api/batch-sendings/foo"); + + self::endpoint()->create([]); + self::assertLastRequest('POST', "/api/batch-sendings"); + + self::endpoint()->update('foo', []); + self::assertLastRequest('PUT', "/api/batch-sendings/foo"); + } + + protected static function endpoint(): BatchSendingsEndpoint + { + return self::dgs()->batchSendings(); + } +} diff --git a/tests/Endpoint/BatchSendingItemsEndpointTest.php b/tests/Endpoint/BatchSendingItemsEndpointTest.php new file mode 100644 index 0000000..1290646 --- /dev/null +++ b/tests/Endpoint/BatchSendingItemsEndpointTest.php @@ -0,0 +1,22 @@ +import(['file' => 'bar']); + self::assertLastRequest('POST', "/api/batch-sendings/foo/items/import", ['file' => 'bar']); + } + + protected static function endpoint(): BatchSendingsItemsEndpoint + { + return self::dgs()->batchSendings()->items('foo'); + } +}