Skip to content

Commit 0a7c052

Browse files
authored
Merge pull request #139 from Sysix/dunnings
add dunnings endpoint
2 parents ff887e7 + ed51c88 commit 0a7c052

File tree

5 files changed

+133
-0
lines changed

5 files changed

+133
-0
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,15 @@ $response = $api->downPaymentInvoice()->document($entityId, true); // get file c
114114
$response = $api->downPaymentInvoice()->document($entityId, true, 'image/*'); // accept only images
115115
```
116116

117+
### Dunnings Endpoint
118+
```php
119+
$response = $api->dunning()->get($entityId);
120+
$response = $api->dunning()->pursue($precedingSalesVoucherId, $data);
121+
$response = $api->dunning()->document($entityId); // get document ID
122+
$response = $api->dunning()->document($entityId, true); // get file content
123+
$response = $api->dunning()->document($entityId, true, 'image/*'); // accept only images
124+
```
125+
117126
### Event Subscriptions Endpooint
118127
```php
119128
$response = $api->event()->get($entityId);

src/Api.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Sysix\LexOffice\Clients\CreditNote;
1717
use Sysix\LexOffice\Clients\DeliveryNote;
1818
use Sysix\LexOffice\Clients\DownPaymentInvoice;
19+
use Sysix\LexOffice\Clients\Dunning;
1920
use Sysix\LexOffice\Clients\Event;
2021
use Sysix\LexOffice\Clients\File;
2122
use Sysix\LexOffice\Clients\Invoice;
@@ -109,6 +110,11 @@ public function downPaymentInvoice(): DownPaymentInvoice
109110
return new DownPaymentInvoice($this);
110111
}
111112

113+
public function dunning(): Dunning
114+
{
115+
return new Dunning($this);
116+
}
117+
112118
public function event(): Event
113119
{
114120
return new Event($this);

src/Clients/Dunning.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Sysix\LexOffice\Clients;
6+
7+
use Sysix\LexOffice\BaseClient;
8+
use Sysix\LexOffice\Clients\Traits\DocumentClientTrait;
9+
use Sysix\LexOffice\Clients\Traits\GetTrait;
10+
use Sysix\LexOffice\Clients\Traits\PursueTrait;
11+
12+
class Dunning extends BaseClient
13+
{
14+
use DocumentClientTrait;
15+
use GetTrait;
16+
use PursueTrait;
17+
18+
protected string $resource = 'dunnings';
19+
}

tests/ApiTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Sysix\LexOffice\Clients\CreditNote;
1212
use Sysix\LexOffice\Clients\DeliveryNote;
1313
use Sysix\LexOffice\Clients\DownPaymentInvoice;
14+
use Sysix\LexOffice\Clients\Dunning;
1415
use Sysix\LexOffice\Clients\Event;
1516
use Sysix\LexOffice\Clients\File;
1617
use Sysix\LexOffice\Clients\Invoice;
@@ -43,6 +44,7 @@ public function testClients(): void
4344
$this->assertInstanceOf(CreditNote::class, $stub->creditNote());
4445
$this->assertInstanceOf(DeliveryNote::class, $stub->deliveryNote());
4546
$this->assertInstanceOf(DownPaymentInvoice::class, $stub->downPaymentInvoice());
47+
$this->assertInstanceOf(Dunning::class, $stub->dunning());
4648
$this->assertInstanceOf(Event::class, $stub->event());
4749
$this->assertInstanceOf(File::class, $stub->file());
4850
$this->assertInstanceOf(Invoice::class, $stub->invoice());

tests/Clients/DunningTest.php

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Sysix\LexOffice\Tests\Clients;
6+
7+
use GuzzleHttp\Psr7\Response;
8+
use Psr\Http\Message\ResponseInterface;
9+
use Sysix\LexOffice\Clients\Dunning;
10+
use Sysix\LexOffice\Tests\TestClient;
11+
12+
class DunningTest extends TestClient
13+
{
14+
public function testGet(): void
15+
{
16+
[$api, $stub] = $this->createClientMockObject(Dunning::class);
17+
18+
$response = $stub->get('resource-id');
19+
20+
$this->assertInstanceOf(ResponseInterface::class, $response);
21+
22+
$this->assertEquals('GET', $api->getRequest()->getMethod());
23+
$this->assertEquals(
24+
$api->apiUrl . '/v1/dunnings/resource-id',
25+
$api->getRequest()->getUri()->__toString()
26+
);
27+
}
28+
29+
public function testPursue(): void
30+
{
31+
[$api, $stub] = $this->createClientMockObject(Dunning::class);
32+
33+
$response = $stub->pursue('resource-id', [
34+
'version' => 0
35+
]);
36+
37+
$this->assertInstanceOf(ResponseInterface::class, $response);
38+
39+
$this->assertEquals('POST', $api->getRequest()->getMethod());
40+
$this->assertEquals(
41+
$api->apiUrl . '/v1/dunnings?precedingSalesVoucherId=resource-id',
42+
$api->getRequest()->getUri()->__toString()
43+
);
44+
}
45+
46+
public function testDocument(): void
47+
{
48+
[$api, $stub] = $this->createClientMockObject(Dunning::class);
49+
50+
$response = $stub->document('resource-id');
51+
52+
$this->assertInstanceOf(ResponseInterface::class, $response);
53+
54+
$this->assertEquals('GET', $api->getRequest()->getMethod());
55+
$this->assertEquals(
56+
$api->apiUrl . '/v1/dunnings/resource-id/document',
57+
$api->getRequest()->getUri()->__toString()
58+
);
59+
}
60+
61+
public function testDocumentContent(): void
62+
{
63+
[$api, $stub] = $this->createClientMultiMockObject(
64+
Dunning::class,
65+
[
66+
new Response(200, ['Content-Type' => 'application/json'], '{"documentFileId": "fake-id"}'),
67+
new Response()
68+
]
69+
);
70+
71+
$response = $stub->document('resource-id', true);
72+
73+
$this->assertInstanceOf(ResponseInterface::class, $response);
74+
75+
$this->assertEquals('GET', $api->getRequest()->getMethod());
76+
$this->assertEquals(
77+
$api->apiUrl . '/v1/files/fake-id',
78+
$api->getRequest()->getUri()->__toString()
79+
);
80+
}
81+
82+
public function testFailedDocumentContent(): void
83+
{
84+
[$api, $stub] = $this->createClientMultiMockObject(
85+
Dunning::class,
86+
[
87+
new Response(500),
88+
new Response()
89+
]
90+
);
91+
92+
$response = $stub->document('resource-id', true);
93+
94+
$this->assertInstanceOf(ResponseInterface::class, $response);
95+
$this->assertEquals(500, $response->getStatusCode());
96+
}
97+
}

0 commit comments

Comments
 (0)