diff --git a/README.md b/README.md index b5632a2..4ee752a 100644 --- a/README.md +++ b/README.md @@ -114,6 +114,15 @@ $response = $api->downPaymentInvoice()->document($entityId, true); // get file c $response = $api->downPaymentInvoice()->document($entityId, true, 'image/*'); // accept only images ``` +### Dunnings Endpoint +```php +$response = $api->dunning()->get($entityId); +$response = $api->dunning()->pursue($precedingSalesVoucherId, $data); +$response = $api->dunning()->document($entityId); // get document ID +$response = $api->dunning()->document($entityId, true); // get file content +$response = $api->dunning()->document($entityId, true, 'image/*'); // accept only images +``` + ### Event Subscriptions Endpooint ```php $response = $api->event()->get($entityId); diff --git a/src/Api.php b/src/Api.php index 224f73f..764268a 100644 --- a/src/Api.php +++ b/src/Api.php @@ -16,6 +16,7 @@ use Sysix\LexOffice\Clients\CreditNote; use Sysix\LexOffice\Clients\DeliveryNote; use Sysix\LexOffice\Clients\DownPaymentInvoice; +use Sysix\LexOffice\Clients\Dunning; use Sysix\LexOffice\Clients\Event; use Sysix\LexOffice\Clients\File; use Sysix\LexOffice\Clients\Invoice; @@ -109,6 +110,11 @@ public function downPaymentInvoice(): DownPaymentInvoice return new DownPaymentInvoice($this); } + public function dunning(): Dunning + { + return new Dunning($this); + } + public function event(): Event { return new Event($this); diff --git a/src/Clients/Dunning.php b/src/Clients/Dunning.php new file mode 100644 index 0000000..fedb58b --- /dev/null +++ b/src/Clients/Dunning.php @@ -0,0 +1,19 @@ +assertInstanceOf(CreditNote::class, $stub->creditNote()); $this->assertInstanceOf(DeliveryNote::class, $stub->deliveryNote()); $this->assertInstanceOf(DownPaymentInvoice::class, $stub->downPaymentInvoice()); + $this->assertInstanceOf(Dunning::class, $stub->dunning()); $this->assertInstanceOf(Event::class, $stub->event()); $this->assertInstanceOf(File::class, $stub->file()); $this->assertInstanceOf(Invoice::class, $stub->invoice()); diff --git a/tests/Clients/DunningTest.php b/tests/Clients/DunningTest.php new file mode 100644 index 0000000..b3d4763 --- /dev/null +++ b/tests/Clients/DunningTest.php @@ -0,0 +1,97 @@ +createClientMockObject(Dunning::class); + + $response = $stub->get('resource-id'); + + $this->assertInstanceOf(ResponseInterface::class, $response); + + $this->assertEquals('GET', $api->getRequest()->getMethod()); + $this->assertEquals( + $api->apiUrl . '/v1/dunnings/resource-id', + $api->getRequest()->getUri()->__toString() + ); + } + + public function testPursue(): void + { + [$api, $stub] = $this->createClientMockObject(Dunning::class); + + $response = $stub->pursue('resource-id', [ + 'version' => 0 + ]); + + $this->assertInstanceOf(ResponseInterface::class, $response); + + $this->assertEquals('POST', $api->getRequest()->getMethod()); + $this->assertEquals( + $api->apiUrl . '/v1/dunnings?precedingSalesVoucherId=resource-id', + $api->getRequest()->getUri()->__toString() + ); + } + + public function testDocument(): void + { + [$api, $stub] = $this->createClientMockObject(Dunning::class); + + $response = $stub->document('resource-id'); + + $this->assertInstanceOf(ResponseInterface::class, $response); + + $this->assertEquals('GET', $api->getRequest()->getMethod()); + $this->assertEquals( + $api->apiUrl . '/v1/dunnings/resource-id/document', + $api->getRequest()->getUri()->__toString() + ); + } + + public function testDocumentContent(): void + { + [$api, $stub] = $this->createClientMultiMockObject( + Dunning::class, + [ + new Response(200, ['Content-Type' => 'application/json'], '{"documentFileId": "fake-id"}'), + new Response() + ] + ); + + $response = $stub->document('resource-id', true); + + $this->assertInstanceOf(ResponseInterface::class, $response); + + $this->assertEquals('GET', $api->getRequest()->getMethod()); + $this->assertEquals( + $api->apiUrl . '/v1/files/fake-id', + $api->getRequest()->getUri()->__toString() + ); + } + + public function testFailedDocumentContent(): void + { + [$api, $stub] = $this->createClientMultiMockObject( + Dunning::class, + [ + new Response(500), + new Response() + ] + ); + + $response = $stub->document('resource-id', true); + + $this->assertInstanceOf(ResponseInterface::class, $response); + $this->assertEquals(500, $response->getStatusCode()); + } +}