-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
244 additions
and
57 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
namespace CodebarAg\Bexio\Dto\PaymentTypes; | ||
|
||
use Exception; | ||
use Illuminate\Support\Arr; | ||
use Saloon\Http\Response; | ||
use Spatie\LaravelData\Data; | ||
|
||
class PaymentTypeDTO extends Data | ||
{ | ||
public function __construct( | ||
public int $id, | ||
public string $name, | ||
) {} | ||
|
||
public static function fromResponse(Response $response): self | ||
{ | ||
if ($response->failed()) { | ||
throw new \Exception('Failed to create DTO from Response'); | ||
} | ||
|
||
$data = $response->json(); | ||
|
||
return self::fromArray($data); | ||
} | ||
|
||
public static function fromArray(array $data): self | ||
{ | ||
if (! $data) { | ||
throw new Exception('Unable to create DTO. Data missing from response.'); | ||
} | ||
|
||
return new self( | ||
id: Arr::get($data, 'id'), | ||
name: Arr::get($data, 'name'), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
src/Requests/PaymentTypes/FetchAListOfPaymentTypesRequest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
namespace CodebarAg\Bexio\Requests\PaymentTypes; | ||
|
||
use CodebarAg\Bexio\Dto\PaymentTypes\PaymentTypeDTO; | ||
use Exception; | ||
use Saloon\Enums\Method; | ||
use Saloon\Http\Request; | ||
use Saloon\Http\Response; | ||
|
||
class FetchAListOfPaymentTypesRequest extends Request | ||
{ | ||
protected Method $method = Method::GET; | ||
|
||
public function __construct( | ||
readonly string $orderBy = 'id', | ||
readonly int $limit = 500, | ||
readonly int $offset = 0, | ||
) {} | ||
|
||
public function resolveEndpoint(): string | ||
{ | ||
return '/2.0/payment_type'; | ||
} | ||
|
||
public function defaultQuery(): array | ||
{ | ||
return [ | ||
'order_by' => $this->orderBy, | ||
'limit' => $this->limit, | ||
'offset' => $this->offset, | ||
]; | ||
} | ||
|
||
public function createDtoFromResponse(Response $response): mixed | ||
{ | ||
if (! $response->successful()) { | ||
throw new Exception('Request was not successful. Unable to create DTO.'); | ||
} | ||
|
||
$res = $response->json(); | ||
|
||
$paymentTypes = collect(); | ||
|
||
foreach ($res as $paymentType) { | ||
$paymentTypes->push(PaymentTypeDTO::fromArray($paymentType)); | ||
} | ||
|
||
return $paymentTypes; | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
tests/Fixtures/Saloon/BusinessActivities/fetch-a-list-of-business-activities.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"statusCode": 200, | ||
"headers": { | ||
"Date": "Mon, 30 Sep 2024 13:36:38 GMT", | ||
"Content-Type": "application\/json", | ||
"Content-Length": "528", | ||
"Connection": "keep-alive", | ||
"ratelimit-reset": "22", | ||
"x-ratelimit-remaining-minute": "999", | ||
"x-ratelimit-limit-minute": "1000", | ||
"ratelimit-remaining": "999", | ||
"ratelimit-limit": "1000", | ||
"Cache-Control": "no-store", | ||
"pragma": "no-cache", | ||
"vary": "Origin", | ||
"access-control-allow-origin": "https:\/\/office.bexio.com", | ||
"via": "1.1 google", | ||
"alt-svc": "h3=\":443\"; ma=86400", | ||
"CF-Cache-Status": "DYNAMIC", | ||
"Server": "cloudflare", | ||
"CF-RAY": "8cb49a5e3bc7cd24-LHR" | ||
}, | ||
"data": "[{\"id\":1,\"name\":\"Administration\",\"default_is_billable\":true,\"default_price_per_hour\":null,\"account_id\":null},{\"id\":2,\"name\":\"Meeting\",\"default_is_billable\":true,\"default_price_per_hour\":null,\"account_id\":null},{\"id\":3,\"name\":\"Projekt Management\",\"default_is_billable\":true,\"default_price_per_hour\":null,\"account_id\":null},{\"id\":4,\"name\":\"Umsetzung\",\"default_is_billable\":true,\"default_price_per_hour\":null,\"account_id\":null},{\"id\":5,\"name\":\"Allgemein\",\"default_is_billable\":true,\"default_price_per_hour\":null,\"account_id\":null}]" | ||
} |
24 changes: 24 additions & 0 deletions
24
tests/Fixtures/Saloon/Languages/fetch-a-list-of-languages.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"statusCode": 200, | ||
"headers": { | ||
"Date": "Mon, 30 Sep 2024 13:33:50 GMT", | ||
"Content-Type": "application\/json", | ||
"Content-Length": "1067", | ||
"Connection": "keep-alive", | ||
"ratelimit-limit": "1000", | ||
"ratelimit-remaining": "999", | ||
"x-ratelimit-remaining-minute": "999", | ||
"x-ratelimit-limit-minute": "1000", | ||
"ratelimit-reset": "10", | ||
"Cache-Control": "no-store", | ||
"pragma": "no-cache", | ||
"vary": "Origin", | ||
"access-control-allow-origin": "https:\/\/office.bexio.com", | ||
"via": "1.1 google", | ||
"alt-svc": "h3=\":443\"; ma=86400", | ||
"CF-Cache-Status": "DYNAMIC", | ||
"Server": "cloudflare", | ||
"CF-RAY": "8cb496447db660e9-LHR" | ||
}, | ||
"data": "[{\"id\":1,\"name\":\"Deutsch\",\"decimal_point\":\".\",\"thousands_separator\":\"'\",\"date_format_id\":1,\"date_format\":\"d.m.Y\",\"iso_639_1\":\"de\"},{\"id\":2,\"name\":\"Franz\\u00f6sisch\",\"decimal_point\":\".\",\"thousands_separator\":\"'\",\"date_format_id\":1,\"date_format\":\"d.m.Y\",\"iso_639_1\":\"fr\"},{\"id\":3,\"name\":\"Italienisch\",\"decimal_point\":\".\",\"thousands_separator\":\"'\",\"date_format_id\":1,\"date_format\":\"d.m.Y\",\"iso_639_1\":\"it\"},{\"id\":4,\"name\":\"Englisch\",\"decimal_point\":\".\",\"thousands_separator\":\"'\",\"date_format_id\":1,\"date_format\":\"d.m.Y\",\"iso_639_1\":\"en\"},{\"id\":5,\"name\":\"Portugiesisch\",\"decimal_point\":\".\",\"thousands_separator\":\"'\",\"date_format_id\":1,\"date_format\":\"d.m.Y\",\"iso_639_1\":\"pt\"},{\"id\":6,\"name\":\"Chinesisch\",\"decimal_point\":\".\",\"thousands_separator\":\"'\",\"date_format_id\":1,\"date_format\":\"d.m.Y\",\"iso_639_1\":\"zh\"},{\"id\":7,\"name\":\"Japanisch\",\"decimal_point\":\".\",\"thousands_separator\":\"'\",\"date_format_id\":1,\"date_format\":\"d.m.Y\",\"iso_639_1\":\"ja\"},{\"id\":8,\"name\":\"Spanisch\",\"decimal_point\":\".\",\"thousands_separator\":\"'\",\"date_format_id\":1,\"date_format\":\"d.m.Y\",\"iso_639_1\":\"es\"}]" | ||
} |
24 changes: 24 additions & 0 deletions
24
tests/Fixtures/Saloon/PaymentTypes/fetch-a-list-of-payment-types.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"statusCode": 200, | ||
"headers": { | ||
"Date": "Mon, 30 Sep 2024 13:32:02 GMT", | ||
"Content-Type": "application\/json", | ||
"Content-Length": "208", | ||
"Connection": "keep-alive", | ||
"ratelimit-remaining": "999", | ||
"ratelimit-reset": "58", | ||
"x-ratelimit-limit-minute": "1000", | ||
"x-ratelimit-remaining-minute": "999", | ||
"ratelimit-limit": "1000", | ||
"Cache-Control": "no-store", | ||
"pragma": "no-cache", | ||
"vary": "Origin", | ||
"access-control-allow-origin": "https:\/\/office.bexio.com", | ||
"via": "1.1 google", | ||
"alt-svc": "h3=\":443\"; ma=86400", | ||
"CF-Cache-Status": "DYNAMIC", | ||
"Server": "cloudflare", | ||
"CF-RAY": "8cb4939f6b4a60ed-LHR" | ||
}, | ||
"data": "[{\"id\":1,\"name\":\"Vorauszahlung\"},{\"id\":2,\"name\":\"Barzahlung\"},{\"id\":3,\"name\":\"EC Karte\"},{\"id\":4,\"name\":\"Rechnung\"},{\"id\":5,\"name\":\"Nachnahme\"},{\"id\":6,\"name\":\"Kreditkarte\"},{\"id\":7,\"name\":\"Bankeinzug\\\/LSV\"}]" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"statusCode": 200, | ||
"headers": { | ||
"Date": "Mon, 30 Sep 2024 13:35:44 GMT", | ||
"Content-Type": "application\/json", | ||
"Content-Length": "16", | ||
"Connection": "keep-alive", | ||
"ratelimit-remaining": "999", | ||
"ratelimit-reset": "16", | ||
"x-ratelimit-limit-minute": "1000", | ||
"x-ratelimit-remaining-minute": "999", | ||
"ratelimit-limit": "1000", | ||
"Cache-Control": "no-store", | ||
"pragma": "no-cache", | ||
"vary": "Origin", | ||
"access-control-allow-origin": "https:\/\/office.bexio.com", | ||
"via": "1.1 google", | ||
"alt-svc": "h3=\":443\"; ma=86400", | ||
"CF-Cache-Status": "DYNAMIC", | ||
"Server": "cloudflare", | ||
"CF-RAY": "8cb4990f0936bd98-LHR" | ||
}, | ||
"data": "{\"success\":true}" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"statusCode": 200, | ||
"headers": { | ||
"Date": "Mon, 30 Sep 2024 13:34:35 GMT", | ||
"Content-Type": "application\/json", | ||
"Content-Length": "363", | ||
"Connection": "keep-alive", | ||
"ratelimit-remaining": "999", | ||
"ratelimit-reset": "25", | ||
"x-ratelimit-limit-minute": "1000", | ||
"x-ratelimit-remaining-minute": "999", | ||
"ratelimit-limit": "1000", | ||
"etag": "d618434bea7ee1cd7f1562e89254c390", | ||
"Cache-Control": "no-store", | ||
"pragma": "no-cache", | ||
"vary": "Origin", | ||
"access-control-allow-origin": "https:\/\/office.bexio.com", | ||
"via": "1.1 google", | ||
"CF-Cache-Status": "DYNAMIC", | ||
"Server": "cloudflare", | ||
"CF-RAY": "8cb4975deb159406-LHR" | ||
}, | ||
"data": "{\"id\":3,\"uuid\":\"4280f7e2-4772-4772-8b42-d8a0173c05ac\",\"name\":\"lib.model.tax.ch.sales_export.name\",\"code\":\"UEX\",\"digit\":\"220\",\"type\":\"not_taxable_turnover\",\"account_id\":105,\"tax_settlement_type\":\"none\",\"value\":0,\"net_tax_value\":null,\"start_year\":null,\"end_year\":null,\"is_active\":true,\"display_name\":\"UEX - Export\\\/Exempt 0.00%\",\"start_month\":null,\"end_month\":null}" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
tests/Requests/PaymentTypes/FetchAListOfPaymentTypesRequestTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
use CodebarAg\Bexio\BexioConnector; | ||
use CodebarAg\Bexio\Requests\PaymentTypes\FetchAListOfPaymentTypesRequest; | ||
use Illuminate\Support\Collection; | ||
use Saloon\Http\Faking\MockResponse; | ||
use Saloon\Laravel\Http\Faking\MockClient; | ||
|
||
it('can perform the request', closure: function () { | ||
$mockClient = new MockClient([ | ||
FetchAListOfPaymentTypesRequest::class => MockResponse::fixture('PaymentTypes/fetch-a-list-of-payment-types'), | ||
]); | ||
|
||
$connector = new BexioConnector; | ||
$connector->withMockClient($mockClient); | ||
|
||
$response = $connector->send(new FetchAListOfPaymentTypesRequest); | ||
|
||
$mockClient->assertSent(FetchAListOfPaymentTypesRequest::class); | ||
|
||
expect($response->dto())->toBeInstanceOf(Collection::class) | ||
->and($response->dto()->count())->toBe(7); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 0 additions & 23 deletions
23
tests/Requests/VatPeriods/FetchAListOfTaxesRequestTest.php
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.