Skip to content

Commit 1a55227

Browse files
committed
Merge remote-tracking branch 'origin/development' into delivery-notes
2 parents 8c463a2 + f4724c1 commit 1a55227

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+265
-183
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
name: New Feature
3+
labels: enhancement
4+
---
5+
6+
## Requirements
7+
8+
- [ ] Updated README.md
9+
- [ ] Add PHPUnit test
10+
- [ ] Added related lexoffice documentation
11+
12+
## Description
13+
14+
Tell us about the new feature
15+
16+
## Related lexoffice documentation
17+
18+
<insert related lexoffice documentation link here>

.php-cs-fixer.dist.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
'multiline_comment_opening_closing' => true,
1515
'multiline_whitespace_before_semicolons' => true,
1616
'native_type_declaration_casing' => true,
17+
'ordered_imports' => ['imports_order' => ['class', 'function', 'const'], 'sort_algorithm' => 'alpha'],
1718
'no_alias_functions' => true,
1819
'no_alias_language_construct_call' => true,
1920
'no_alternative_syntax' => true,

README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ $response = $api->invoice()->get($entityId);
9595
$response = $api->invoice()->create($data);
9696
$response = $api->invoice()->document($entityId); // get document ID
9797
$response = $api->invoice()->document($entityId, true); // get file content
98+
$response = $api->invoice()->document($entityId, true, 'image/*'); // accept only images
99+
$response = $api->invoice()->document($entityId, true, 'application/xml'); // get XRechung XML File (if possible)
98100
```
99101

100102
### Down Payment Invoices Endpoint
@@ -104,6 +106,8 @@ $response = $api->downPaymentInvoice()->get($entityId);
104106
$response = $api->downPaymentInvoice()->create($data);
105107
$response = $api->downPaymentInvoice()->document($entityId); // get document ID
106108
$response = $api->downPaymentInvoice()->document($entityId, true); // get file content
109+
$response = $api->downPaymentInvoice()->document($entityId, true, 'image/*'); // accept only images
110+
$response = $api->downPaymentInvoice()->document($entityId, true, 'application/xml'); // get XRechung XML File (if possible)
107111
```
108112

109113
### Order Confirmation Endpoint
@@ -113,6 +117,8 @@ $response = $api->orderConfirmation()->get($entityId);
113117
$response = $api->orderConfirmation()->create($data);
114118
$response = $api->orderConfirmation()->document($entityId); // get document ID
115119
$response = $api->orderConfirmation()->document($entityId, true); // get file content
120+
$response = $api->orderConfirmation()->document($entityId, true, 'image/*'); // accept only images
121+
$response = $api->orderConfirmation()->document($entityId, true, 'application/xml'); // get XRechung XML File (if possible)
116122
```
117123

118124
### Quotation Endpoint
@@ -122,6 +128,8 @@ $response = $api->quotation()->get($entityId);
122128
$response = $api->quotation()->create($data);
123129
$response = $api->quotation()->document($entityId); // get document ID
124130
$response = $api->quotation()->document($entityId, true); // get file content
131+
$response = $api->quotation()->document($entityId, true, 'image/*'); // accept only images
132+
$response = $api->quotation()->document($entityId, true, 'application/xml'); // get XRechung XML File (if possible)
125133
```
126134

127135
### Voucher Endpoint
@@ -131,6 +139,8 @@ $response = $api->voucher()->create($data);
131139
$response = $api->voucher()->update($entityId, $data);
132140
$response = $api->voucher()->document($entityId); // get document ID
133141
$response = $api->voucher()->document($entityId, true); // get file content
142+
$response = $api->voucher()->document($entityId, true, 'image/*'); // accept only images
143+
$response = $api->voucher()->document($entityId, true, 'application/xml'); // get XRechung XML File (if possible)
134144
$response = $api->voucher()->upload($entitiyId, $filepath);
135145
```
136146

@@ -142,6 +152,8 @@ $response = $api->creditNote()->get($entityId);
142152
$response = $api->creditNote()->create($data);
143153
$response = $api->creditNote()->document($entityId); // get document ID
144154
$response = $api->creditNote()->document($entityId, true); // get file content
155+
$response = $api->creditNote()->document($entityId, true, 'image/*'); // accept only images
156+
$response = $api->creditNote()->document($entityId, true, 'application/xml'); // get XRechung XML File (if possible)
145157
```
146158

147159
### Payment Endpoint
@@ -230,7 +242,9 @@ $response = $client->getPage(0);
230242
### File Endpoint
231243
```php
232244
$response = $api->file()->upload($filePath, $voucherType);
233-
$response = $api->file()->get($entityId);
245+
$response = $api->file()->get($entityId); // accept every file
246+
$response = $api->file()->get($entityId, 'image/*'); // accept only images
247+
$response = $api->file()->get($entityId, 'application/xml'); // get XRechung XML File (if possible)
234248
```
235249

236250

src/Api.php

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,17 @@
44

55
namespace Sysix\LexOffice;
66

7+
use GuzzleHttp\Psr7\Request;
78
use GuzzleHttp\Psr7\Uri;
9+
use Psr\Http\Client\ClientInterface;
10+
use Psr\Http\Message\RequestInterface;
11+
use Psr\Http\Message\ResponseInterface;
12+
use Psr\Http\Message\UriInterface;
13+
use SensitiveParameter;
814
use Sysix\LexOffice\Clients\Contact;
915
use Sysix\LexOffice\Clients\Country;
1016
use Sysix\LexOffice\Clients\CreditNote;
17+
use Sysix\LexOffice\Clients\DeliveryNote;
1118
use Sysix\LexOffice\Clients\DownPaymentInvoice;
1219
use Sysix\LexOffice\Clients\Event;
1320
use Sysix\LexOffice\Clients\File;
@@ -21,31 +28,23 @@
2128
use Sysix\LexOffice\Clients\RecurringTemplate;
2229
use Sysix\LexOffice\Clients\Voucher;
2330
use Sysix\LexOffice\Clients\VoucherList;
24-
use GuzzleHttp\Psr7\Request;
25-
use Psr\Http\Client\ClientInterface;
26-
use Psr\Http\Message\RequestInterface;
27-
use Psr\Http\Message\ResponseInterface;
28-
use Psr\Http\Message\UriInterface;
29-
use SensitiveParameter;
30-
use Sysix\LexOffice\Clients\DeliveryNote;
31+
use Sysix\LexOffice\Interfaces\ApiInterface;
32+
3133

32-
class Api
34+
class Api implements ApiInterface
3335
{
3436
public string $apiUrl = 'https://api.lexoffice.io';
3537

3638
protected string $apiVersion = 'v1';
3739

38-
public RequestInterface $request;
40+
protected RequestInterface $request;
3941

4042
public function __construct(
4143
#[SensitiveParameter] protected string $apiKey,
4244
protected ClientInterface $client
4345
) {
4446
}
4547

46-
/**
47-
* @param string[] $headers
48-
*/
4948
public function newRequest(string $method, string $resource, array $headers = []): self
5049
{
5150
$this->setRequest(
@@ -57,9 +56,11 @@ public function newRequest(string $method, string $resource, array $headers = []
5756

5857
public function setRequest(RequestInterface $request): self
5958
{
60-
$request = $request
61-
->withHeader('Authorization', 'Bearer ' . $this->apiKey)
62-
->withHeader('Accept', 'application/json');
59+
$request = $request->withHeader('Authorization', 'Bearer ' . $this->apiKey);
60+
61+
if (!$request->hasHeader('Accept')) {
62+
$request = $request->withHeader('Accept', 'application/json');
63+
}
6364

6465
if (!$request->hasHeader('Content-Type') && in_array($request->getMethod(), ['POST', 'PUT'], true)) {
6566
$request = $request->withHeader('Content-Type', 'application/json');
@@ -70,16 +71,21 @@ public function setRequest(RequestInterface $request): self
7071
return $this;
7172
}
7273

73-
protected function createApiUri(string $resource): UriInterface
74+
public function getRequest(): RequestInterface
7475
{
75-
return new Uri($this->apiUrl . '/' . $this->apiVersion . '/' . $resource);
76+
return $this->request;
7677
}
7778

7879
public function getResponse(): ResponseInterface
7980
{
8081
return $this->client->sendRequest($this->request);
8182
}
8283

84+
protected function createApiUri(string $resource): UriInterface
85+
{
86+
return new Uri($this->apiUrl . '/' . $this->apiVersion . '/' . $resource);
87+
}
88+
8389
public function contact(): Contact
8490
{
8591
return new Contact($this);

src/BaseClient.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@
55
namespace Sysix\LexOffice;
66

77
use Psr\Http\Message\ResponseInterface;
8+
use Sysix\LexOffice\Interfaces\ApiInterface;
9+
use Sysix\LexOffice\Interfaces\ClientInterface;
810

911
abstract class BaseClient implements ClientInterface
1012
{
1113
protected string $resource;
1214

1315
public function __construct(
14-
protected Api $api
16+
protected ApiInterface $api
1517
) {
1618
}
1719

src/ClientInterface.php

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/Clients/Country.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
namespace Sysix\LexOffice\Clients;
66

7-
use Sysix\LexOffice\BaseClient;
87
use Psr\Http\Message\ResponseInterface;
8+
use Sysix\LexOffice\BaseClient;
99

1010
class Country extends BaseClient
1111
{

src/Clients/Event.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
namespace Sysix\LexOffice\Clients;
66

7+
use Psr\Http\Message\ResponseInterface;
78
use Sysix\LexOffice\BaseClient;
89
use Sysix\LexOffice\Clients\Traits\CreateTrait;
910
use Sysix\LexOffice\Clients\Traits\DeleteTrait;
10-
use Psr\Http\Message\ResponseInterface;
1111

1212
class Event extends BaseClient
1313
{

src/Clients/File.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,25 @@
44

55
namespace Sysix\LexOffice\Clients;
66

7-
use Sysix\LexOffice\BaseClient;
8-
use Sysix\LexOffice\Clients\Traits\GetTrait;
9-
use Sysix\LexOffice\Exceptions\LexOfficeApiException;
107
use Psr\Http\Message\ResponseInterface;
8+
use Sysix\LexOffice\BaseClient;
119
use Sysix\LexOffice\Config\FileClientConfig;
10+
use Sysix\LexOffice\Exceptions\LexOfficeApiException;
1211
use Sysix\LexOffice\Utils;
1312

1413
class File extends BaseClient
1514
{
16-
use GetTrait;
17-
1815
protected string $resource = 'files';
1916

17+
public function get(string $id, string $acceptHeader = '*/*'): ResponseInterface
18+
{
19+
$this->api->newRequest('GET', $this->resource . '/' . rawurlencode($id));
20+
21+
$this->api->setRequest($this->api->getRequest()->withHeader('Accept', $acceptHeader));
22+
23+
return $this->api->getResponse();
24+
}
25+
2026
/**
2127
* @throws LexOfficeApiException
2228
*/
@@ -38,7 +44,7 @@ public function upload(string $filepath, string $type): ResponseInterface
3844
'Content-Type' => 'multipart/form-data; boundary=' . $body->getBoundary()
3945
]);
4046

41-
$api->request = $api->request->withBody($body);
47+
$api->setRequest($api->getRequest()->withBody($body));
4248

4349
return $api->getResponse();
4450
}

src/Clients/PaymentCondition.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
namespace Sysix\LexOffice\Clients;
66

7-
use Sysix\LexOffice\BaseClient;
87
use Psr\Http\Message\ResponseInterface;
8+
use Sysix\LexOffice\BaseClient;
99

1010
class PaymentCondition extends BaseClient
1111
{

0 commit comments

Comments
 (0)