Skip to content

Commit 8c463a2

Browse files
committed
add delivery-notes endpoint
1 parent 3a5dd29 commit 8c463a2

File tree

5 files changed

+217
-33
lines changed

5 files changed

+217
-33
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,15 @@ $response = $client->update($entityId, $data);
7979
$response = $api->country()->getAll();
8080
```
8181

82+
### Deliverys Notes Endpoint
83+
```php
84+
$voucherList = $api->deliveryNote()->getVoucherListClient(); // see VoucherlistClient Documentation
85+
$response = $api->deliveryNote()->get($entityId);
86+
$response = $api->deliveryNote()->create($data);
87+
$response = $api->deliveryNote()->document($entityId); // get document ID
88+
$response = $api->deliveryNote()->document($entityId, true); // get file content
89+
```
90+
8291
### Invoices Endpoint
8392
```php
8493
$voucherList = $api->invoice()->getVoucherListClient(); // see VoucherlistClient Documentation

src/Api.php

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
use Psr\Http\Message\ResponseInterface;
2828
use Psr\Http\Message\UriInterface;
2929
use SensitiveParameter;
30+
use Sysix\LexOffice\Clients\DeliveryNote;
3031

3132
class Api
3233
{
@@ -89,19 +90,33 @@ public function country(): Country
8990
return new Country($this);
9091
}
9192

93+
public function creditNote(): CreditNote
94+
{
95+
return new CreditNote($this);
96+
}
97+
98+
public function deliveryNote(): DeliveryNote
99+
{
100+
return new DeliveryNote($this);
101+
}
102+
public function downPaymentInvoice(): DownPaymentInvoice
103+
{
104+
return new DownPaymentInvoice($this);
105+
}
106+
92107
public function event(): Event
93108
{
94109
return new Event($this);
95110
}
96111

97-
public function invoice(): Invoice
112+
public function file(): File
98113
{
99-
return new Invoice($this);
114+
return new File($this);
100115
}
101116

102-
public function downPaymentInvoice(): DownPaymentInvoice
117+
public function invoice(): Invoice
103118
{
104-
return new DownPaymentInvoice($this);
119+
return new Invoice($this);
105120
}
106121

107122
public function orderConfirmation(): OrderConfirmation
@@ -118,44 +133,34 @@ public function paymentCondition(): PaymentCondition
118133
{
119134
return new PaymentCondition($this);
120135
}
121-
122-
public function creditNote(): CreditNote
136+
public function postingCategory(): PostingCategory
123137
{
124-
return new CreditNote($this);
138+
return new PostingCategory($this);
125139
}
126140

127-
public function quotation(): Quotation
141+
public function profile(): Profile
128142
{
129-
return new Quotation($this);
143+
return new Profile($this);
130144
}
131145

132-
public function voucher(): Voucher
146+
public function quotation(): Quotation
133147
{
134-
return new Voucher($this);
148+
return new Quotation($this);
135149
}
136150

137151
public function recurringTemplate(): RecurringTemplate
138152
{
139153
return new RecurringTemplate($this);
140154
}
141155

142-
public function voucherlist(): VoucherList
143-
{
144-
return new VoucherList($this);
145-
}
146-
147-
public function profile(): Profile
156+
public function voucher(): Voucher
148157
{
149-
return new Profile($this);
158+
return new Voucher($this);
150159
}
151160

152-
public function postingCategory(): PostingCategory
161+
public function voucherlist(): VoucherList
153162
{
154-
return new PostingCategory($this);
163+
return new VoucherList($this);
155164
}
156165

157-
public function file(): File
158-
{
159-
return new File($this);
160-
}
161166
}

src/Clients/DeliveryNote.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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\CreateTrait;
9+
use Sysix\LexOffice\Clients\Traits\DocumentClientTrait;
10+
use Sysix\LexOffice\Clients\Traits\GetTrait;
11+
use Sysix\LexOffice\Clients\Traits\VoucherListTrait;
12+
13+
class DeliveryNote extends BaseClient
14+
{
15+
use GetTrait;
16+
use CreateTrait;
17+
use VoucherListTrait;
18+
use DocumentClientTrait;
19+
20+
protected string $resource = 'delivery-notes';
21+
22+
/** @var string[] */
23+
protected array $voucherListTypes = ['deliverynote'];
24+
}

tests/ApiTest.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use Sysix\LexOffice\Clients\RecurringTemplate;
2323
use GuzzleHttp\Psr7\Response;
2424
use Psr\Http\Message\ResponseInterface;
25+
use Sysix\LexOffice\Clients\DeliveryNote;
2526

2627
class ApiTest extends TestClient
2728
{
@@ -37,22 +38,23 @@ public function testClients(): void
3738
{
3839
$stub = $this->createApiMockObject(new Response());
3940

40-
$this->assertInstanceOf(Country::class, $stub->country());
4141
$this->assertInstanceOf(Contact::class, $stub->contact());
42+
$this->assertInstanceOf(Country::class, $stub->country());
43+
$this->assertInstanceOf(CreditNote::class, $stub->creditNote());
44+
$this->assertInstanceOf(DeliveryNote::class, $stub->deliveryNote());
45+
$this->assertInstanceOf(DownPaymentInvoice::class, $stub->downPaymentInvoice());
4246
$this->assertInstanceOf(Event::class, $stub->event());
47+
$this->assertInstanceOf(File::class, $stub->file());
4348
$this->assertInstanceOf(Invoice::class, $stub->invoice());
44-
$this->assertInstanceOf(DownPaymentInvoice::class, $stub->downPaymentInvoice());
4549
$this->assertInstanceOf(OrderConfirmation::class, $stub->orderConfirmation());
46-
$this->assertInstanceOf(Quotation::class, $stub->quotation());
47-
$this->assertInstanceOf(Voucher::class, $stub->voucher());
48-
$this->assertInstanceOf(VoucherList::class, $stub->voucherlist());
49-
$this->assertInstanceOf(Profile::class, $stub->profile());
50-
$this->assertInstanceOf(CreditNote::class, $stub->creditNote());
5150
$this->assertInstanceOf(Payment::class, $stub->payment());
5251
$this->assertInstanceOf(PaymentCondition::class, $stub->paymentCondition());
53-
$this->assertInstanceOf(File::class, $stub->file());
54-
$this->assertInstanceOf(RecurringTemplate::class, $stub->recurringTemplate());
5552
$this->assertInstanceOf(PostingCategory::class, $stub->postingCategory());
53+
$this->assertInstanceOf(Profile::class, $stub->profile());
54+
$this->assertInstanceOf(Quotation::class, $stub->quotation());
55+
$this->assertInstanceOf(RecurringTemplate::class, $stub->recurringTemplate());
56+
$this->assertInstanceOf(Voucher::class, $stub->voucher());
57+
$this->assertInstanceOf(VoucherList::class, $stub->voucherlist());
5658
}
5759

5860
public function testApiUrl(): void

tests/Clients/DeliveryNoteTest.php

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
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\DeliveryNote;
10+
use Sysix\LexOffice\Clients\VoucherList;
11+
use Sysix\LexOffice\Tests\TestClient;
12+
13+
class DeliveryNoteTest extends TestClient
14+
{
15+
public function testGet(): void
16+
{
17+
[$api, $stub] = $this->createClientMockObject(DeliveryNote::class);
18+
19+
$response = $stub->get('resource-id');
20+
21+
$this->assertInstanceOf(ResponseInterface::class, $response);
22+
23+
$this->assertEquals('GET', $api->request->getMethod());
24+
$this->assertEquals(
25+
$api->apiUrl . '/v1/delivery-notes/resource-id',
26+
$api->request->getUri()->__toString()
27+
);
28+
}
29+
30+
public function testCreate(): void
31+
{
32+
[$api, $stub] = $this->createClientMockObject(DeliveryNote::class);
33+
34+
$response = $stub->create([
35+
'version' => 0
36+
]);
37+
38+
$this->assertInstanceOf(ResponseInterface::class, $response);
39+
40+
$this->assertEquals('POST', $api->request->getMethod());
41+
$this->assertEquals(
42+
$api->apiUrl . '/v1/delivery-notes',
43+
$api->request->getUri()->__toString()
44+
);
45+
}
46+
47+
public function testGetPage(): void
48+
{
49+
$this->expectDeprecationV1Warning('getPage');
50+
51+
[$api, $stub] = $this->createClientMockObject(DeliveryNote::class);
52+
53+
$response = $stub->getPage(0);
54+
55+
$this->assertInstanceOf(ResponseInterface::class, $response);
56+
57+
$this->assertEquals('GET', $api->request->getMethod());
58+
$this->assertEquals(
59+
$api->apiUrl . '/v1/voucherlist?page=0&sort=voucherNumber%2CDESC&voucherType=deliverynote&voucherStatus=draft%2Copen%2Cpaid%2Cpaidoff%2Cvoided%2Caccepted%2Crejected&size=100',
60+
$api->request->getUri()->__toString()
61+
);
62+
}
63+
64+
public function testGetAll(): void
65+
{
66+
$this->expectDeprecationV1Warning('getAll');
67+
68+
[$api, $stub] = $this->createClientMultiMockObject(
69+
DeliveryNote::class,
70+
[new Response(200, [], '{"content": [], "totalPages": 1}')]
71+
);
72+
73+
$response = $stub->getAll();
74+
75+
$this->assertInstanceOf(ResponseInterface::class, $response);
76+
77+
$this->assertEquals('GET', $api->request->getMethod());
78+
$this->assertEquals(
79+
$api->apiUrl . '/v1/voucherlist?page=0&sort=voucherNumber%2CDESC&voucherType=deliverynote&voucherStatus=draft%2Copen%2Cpaid%2Cpaidoff%2Cvoided%2Caccepted%2Crejected&size=100',
80+
$api->request->getUri()->__toString()
81+
);
82+
}
83+
84+
public function testGetVoucherListClient(): void
85+
{
86+
[, $stub] = $this->createClientMockObject(DeliveryNote::class);
87+
88+
$client = $stub->getVoucherListClient();
89+
90+
$this->assertInstanceOf(VoucherList::class, $client);
91+
}
92+
93+
public function testDocument(): void
94+
{
95+
[$api, $stub] = $this->createClientMockObject(DeliveryNote::class);
96+
97+
$response = $stub->document('resource-id');
98+
99+
$this->assertInstanceOf(ResponseInterface::class, $response);
100+
101+
$this->assertEquals('GET', $api->request->getMethod());
102+
$this->assertEquals(
103+
$api->apiUrl . '/v1/delivery-notes/resource-id/document',
104+
$api->request->getUri()->__toString()
105+
);
106+
}
107+
108+
public function testDocumentContent(): void
109+
{
110+
[$api, $stub] = $this->createClientMultiMockObject(
111+
DeliveryNote::class,
112+
[
113+
new Response(200, ['Content-Type' => 'application/json'], '{"documentFileId": "fake-id"}'),
114+
new Response()
115+
]
116+
);
117+
118+
$response = $stub->document('resource-id', true);
119+
120+
$this->assertInstanceOf(ResponseInterface::class, $response);
121+
122+
$this->assertEquals('GET', $api->request->getMethod());
123+
$this->assertEquals(
124+
$api->apiUrl . '/v1/files/fake-id',
125+
$api->request->getUri()->__toString()
126+
);
127+
}
128+
129+
public function testFailedDocumentContent(): void
130+
{
131+
[$api, $stub] = $this->createClientMultiMockObject(
132+
DeliveryNote::class,
133+
[
134+
new Response(500),
135+
new Response()
136+
]
137+
);
138+
139+
$response = $stub->document('resource-id', true);
140+
141+
$this->assertInstanceOf(ResponseInterface::class, $response);
142+
$this->assertEquals(500, $response->getStatusCode());
143+
}
144+
}

0 commit comments

Comments
 (0)