diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index ea68144..50d4706 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -13,17 +13,27 @@ jobs: fail-fast: true matrix: os: [ubuntu-latest] - php: [8.0, 8.1] - laravel: [8.*, 9.*] + php: [8.1, 8.2, 8.3] + laravel: [9.*, 10.*, 11.*] stability: [prefer-stable] include: - - laravel: 8.* - testbench: 6.* - laravel: 9.* testbench: 7.* + phpunit: ^9.5.10 + illuminate_contracts: ^9.0 + - laravel: 10.* + testbench: 8.* + phpunit: ^9.6 + illuminate_contracts: ^10.0 + - laravel: 11.* + testbench: 9.* + phpunit: ^10.5 + illuminate_contracts: ^11.0 + exclude: + - php: 8.1 + laravel: 11.* name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }} - steps: - name: Checkout code uses: actions/checkout@v3 @@ -42,7 +52,7 @@ jobs: - name: Install dependencies run: | - composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update + composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" "phpunit/phpunit:${{ matrix.phpunit }}" "illuminate/contracts:${{ matrix.illuminate_contracts }}" --no-interaction --no-update composer update --${{ matrix.stability }} --prefer-dist --no-interaction - name: List Installed Dependencies diff --git a/composer.json b/composer.json index 2658a9a..6de2215 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,6 @@ "name": "print-one/print-one-laravel", "description": "This is my package print-one", "keywords": [ - "nexibi", "laravel", "print.one", "printing", @@ -28,19 +27,21 @@ { "name": "Print.one Development", "email": "dev@print.one", - "role": "Developer" + "role": "Developer" } ], "require": { - "php": "^8.0", + "php": "^8.1", + "ext-iconv": "*", "guzzlehttp/guzzle": "^7.5", - "illuminate/contracts": "^8.0|^9.0", + "illuminate/contracts": "^9.0", + "laravel/framework": "9.*", + "orchestra/testbench": "7.*", + "phpunit/phpunit": "^9.5.10", "spatie/laravel-package-tools": "^1.12.0|^1.13.6" }, "require-dev": { - "laravel/pint": "^1.0", - "orchestra/testbench": "^6.0|^7.0", - "phpunit/phpunit": "^9.5" + "laravel/pint": "^1.0" }, "autoload": { "psr-4": { diff --git a/src/Contracts/PrintOneApi.php b/src/Contracts/PrintOneApi.php index 1f1d202..26174c6 100644 --- a/src/Contracts/PrintOneApi.php +++ b/src/Contracts/PrintOneApi.php @@ -5,18 +5,19 @@ use Illuminate\Support\Collection; use Nexibi\PrintOne\DTO\Address; use Nexibi\PrintOne\DTO\Order; -use Nexibi\PrintOne\DTO\Postcard; use Nexibi\PrintOne\DTO\Template; +use Nexibi\PrintOne\Enums\Finish; interface PrintOneApi { - public function templates(int $page, int $size): Collection; + public function templates(int $page, int $limit): Collection; public function order( - Postcard $postcard, - array $mergeVariables, + string $templateId, + Finish $finish, + Address $recipient, Address $sender, - Address $recipient + array $mergeVariables = [] ): Order; public function preview(Template $template, int $retryTimes = 5): string; diff --git a/src/DTO/Address.php b/src/DTO/Address.php index 897d4ec..b0f227e 100644 --- a/src/DTO/Address.php +++ b/src/DTO/Address.php @@ -16,6 +16,17 @@ public function __construct( // } + public static function fromArray(array $data): self + { + return new Address( + name: $data['name'], + address: $data['address'], + postalCode: $data['postalCode'], + city: $data['city'], + country: $data['country'] + ); + } + public function toArray(): array { return [ diff --git a/src/DTO/Order.php b/src/DTO/Order.php index 5be22ba..9e4497a 100644 --- a/src/DTO/Order.php +++ b/src/DTO/Order.php @@ -4,12 +4,15 @@ use Carbon\Carbon; use Illuminate\Contracts\Support\Arrayable; +use Nexibi\PrintOne\Enums\Finish; class Order implements Arrayable { public function __construct( public string $id, public string $status, + public string $templateId, + public ?Finish $finish, public Carbon $createdAt, public bool $isBillable, ) { @@ -21,19 +24,22 @@ public static function fromArray(array $data): self return new Order( id: $data['id'], status: $data['status'], + templateId: $data['templateId'], + finish: Finish::tryFrom($data['finish']), createdAt: Carbon::parse($data['createdAt']), isBillable: $data['isBillable'] ); } - public function toArray(): array { return [ 'id' => $this->id, 'status' => $this->status, + 'templateId' => $this->templateId, + 'finish' => $this->finish, 'createdAt' => $this->createdAt->toDateTimeString(), - 'isBillable' => $this->isBillable + 'isBillable' => $this->isBillable, ]; } } diff --git a/src/DTO/Postcard.php b/src/DTO/Postcard.php deleted file mode 100644 index a898c1c..0000000 --- a/src/DTO/Postcard.php +++ /dev/null @@ -1,32 +0,0 @@ - $this->front, - 'back' => $this->back, - 'format' => $this->format, - ]; - } - - public function toJson($options = 0): string - { - return json_encode($this->toArray(), $options); - } -} diff --git a/src/DTO/Template.php b/src/DTO/Template.php index 19d3477..1f08dd0 100644 --- a/src/DTO/Template.php +++ b/src/DTO/Template.php @@ -3,13 +3,14 @@ namespace Nexibi\PrintOne\DTO; use Carbon\Carbon; +use Nexibi\PrintOne\Enums\Format; class Template { public function __construct( public string $id, public string $name, - public string $format, + public ?Format $format, public int $version, public Carbon $updatedAt ) { @@ -18,10 +19,12 @@ public function __construct( public static function fromArray(array $array): self { + $format = (is_string($array['format'])) ? Format::tryFrom($array['format']) : $array['format']; + return new self( id: $array['id'], name: $array['name'], - format: $array['format'], + format: $format, version: (int) $array['version'], updatedAt: Carbon::parse($array['updatedAt'], 'UTC'), ); diff --git a/src/Enums/Finish.php b/src/Enums/Finish.php new file mode 100644 index 0000000..8739d2d --- /dev/null +++ b/src/Enums/Finish.php @@ -0,0 +1,9 @@ +templates = collect($templates); } - public function templates(int $page, int $size): Collection + public function templates(int $page, int $limit): Collection { return $this->templates; } - public function order(Postcard $postcard, array $mergeVariables, Address $sender, Address $recipient): Order + public function order(string $templateId, Finish $finish, Address $recipient, Address $sender, array $mergeVariables = []): Order { - $this->orders->push(['postcard' => $postcard, 'from' => $sender, 'to' => $recipient]); + $this->orders->push(['templateId' => $templateId, 'finish' => $finish, 'from' => $sender, 'to' => $recipient]); return new Order( - id: Str::uuid(), status: 'status', createdAt: now(), isBillable: false + id: Str::uuid(), status: 'status', templateId: $templateId, finish: $finish, createdAt: now(), isBillable: false ); } - public function preview(Template $template, int $timeout = 30): string + public function preview(Template $template, int $retryTimes = 30): string { $this->viewed->push($template); return ''; } - public function assertOrdered(Postcard $postcard, Address $from, Address $to): void + public function assertOrdered(string $templateId, Finish $finish, Address $from, Address $to): void { - $order = $this->orders->where('postcard', $postcard)->where('from', $from)->where('to', $to)->first(); + $order = $this->orders->where('templateId', $templateId) + ->where('finish', $finish) + ->where('from', $from)->where('to', $to)->first(); Assert::assertNotNull( $order, - "Failed asserting postcard with front: '{$postcard->front}' and back: '{$postcard->back}' was ordered from {$from->name} to {$to->name}" + "Failed asserting postcard with template ID: '{$templateId}' and finish: '{$finish->value}' was ordered from {$from->name} to {$to->name}" ); } diff --git a/src/Facades/PrintOne.php b/src/Facades/PrintOne.php index 1e36526..80111a3 100644 --- a/src/Facades/PrintOne.php +++ b/src/Facades/PrintOne.php @@ -8,6 +8,7 @@ /** * @see \Nexibi\PrintOne\PrintOne + * * @mixin \Nexibi\PrintOne\PrintOne */ class PrintOne extends Facade diff --git a/src/PrintOne.php b/src/PrintOne.php index ea0675a..0d91a02 100755 --- a/src/PrintOne.php +++ b/src/PrintOne.php @@ -8,15 +8,16 @@ use Nexibi\PrintOne\Contracts\PrintOneApi; use Nexibi\PrintOne\DTO\Address; use Nexibi\PrintOne\DTO\Order; -use Nexibi\PrintOne\DTO\Postcard; use Nexibi\PrintOne\DTO\Template; +use Nexibi\PrintOne\Enums\Finish; +use Nexibi\PrintOne\Exceptions\CouldNotFetchOrder; use Nexibi\PrintOne\Exceptions\CouldNotFetchPreview; use Nexibi\PrintOne\Exceptions\CouldNotFetchTemplates; use Nexibi\PrintOne\Exceptions\CouldNotPlaceOrder; class PrintOne implements PrintOneApi { - private string $baseUrl = 'https://api.print.one/v1/'; + private string $baseUrl = 'https://api.print.one/v2/'; private PendingRequest $http; @@ -28,9 +29,12 @@ public function __construct() ]); } - public function templates(int $page, int $size): Collection + /** + * @throws CouldNotFetchOrder + */ + public function templates(int $page = 0, int $limit = 20): Collection { - $response = $this->http->get('templates', ['page' => $page, 'size' => $size]); + $response = $this->http->get('templates', ['page' => $page, 'limit' => $limit]); if ($response->serverError()) { throw new CouldNotFetchTemplates( @@ -40,25 +44,22 @@ public function templates(int $page, int $size): Collection return $response ->collect('data') - ->map(fn($data) => Template::fromArray($data)); + ->map(fn ($data) => Template::fromArray($data)); } - public function order(Postcard $postcard, array $mergeVariables, Address $sender, Address $recipient): Order + public function order(string $templateId, Finish $finish, Address $recipient, Address $sender, array $mergeVariables = []): Order { $data = [ 'sender' => $sender->toArray(), 'recipient' => $recipient->toArray(), - 'format' => $postcard->format, - 'pages' => (object)[ - "1" => $postcard->front, - "2" => $postcard->back, - ], + 'templateId' => $templateId, + 'finish' => $finish->value, ]; - if (!empty($mergeVariables)) { - $data['mergeVariables'] = $mergeVariables; + if (! empty($mergeVariables)) { + $data['mergeVariables'] = (object) $mergeVariables; } - + $response = $this->http->post('orders', $data); if ($response->clientError()) { @@ -73,7 +74,7 @@ public function order(Postcard $postcard, array $mergeVariables, Address $sender return Order::fromArray($response->json()); } - + /** * @throws CouldNotFetchOrder */ @@ -83,28 +84,33 @@ public function getOrder(string $orderId): Order if ($response->failed()) { throw new CouldNotFetchOrder('Something went wrong while fetching the order from the Print.one API.'); } - + return Order::fromArray($response->json()); } - + /** * @throws CouldNotFetchPreview */ - public function preview(Template $template, int $retryTimes = 5): string + public function preview(Template $template, int $retryTimes = 10): string { - $response = $this->http->post("templates/preview/{$template->id}/{$template->version}"); + $response = $this->http->post("templates/preview/{$template->id}/{$template->version}", ['mergeVariables' => (object) []]); + if ($response->failed()) { throw new CouldNotFetchPreview('Something went wrong while fetching the preview from the Print.one API.'); } - $previewUrl = $response->json('url'); + $responseData = collect($response->json()) + ->map(fn (array $a) => (object) $a); + + // The first item is often the front side of the template + $previewUrl = $responseData->first()->url; $response = rescue( - fn() => $this->http->retry($retryTimes, 1000)->get($previewUrl), - fn($error) => $error->response + fn () => $this->http->retry($retryTimes, 1000)->get($previewUrl), + fn ($error) => $error->response ); - if (!$response || $response->failed()) { + if (! $response || $response->failed()) { throw new CouldNotFetchPreview('Something went wrong while fetching the preview from the Print.one API.'); } diff --git a/tests/PrintOneTest.php b/tests/PrintOneTest.php index 74b023b..2b0f1aa 100644 --- a/tests/PrintOneTest.php +++ b/tests/PrintOneTest.php @@ -11,8 +11,8 @@ use Illuminate\Support\Str; use Nexibi\PrintOne\DTO\Address; use Nexibi\PrintOne\DTO\Order; -use Nexibi\PrintOne\DTO\Postcard; use Nexibi\PrintOne\DTO\Template; +use Nexibi\PrintOne\Enums\Finish; use Nexibi\PrintOne\Enums\Format; use Nexibi\PrintOne\Exceptions\CouldNotFetchPreview; use Nexibi\PrintOne\Exceptions\CouldNotFetchTemplates; @@ -76,36 +76,36 @@ public function test_it_can_retrieve_templates(): void ]; Http::fake([ - 'https://api.print.one/v1/templates?*' => Http::response($fakeResponse), + 'https://api.print.one/v2/templates?*' => Http::response($fakeResponse), ]); - $templates = PrintOne::templates(page: 1, size: 50); + $templates = PrintOne::templates(page: 1, limit: 50); $this->assertInstanceOf(Collection::class, $templates); $this->assertContainsOnlyInstancesOf(Template::class, $templates); $this->assertEquals($fakeResponse['data'][0]['id'], $templates[0]->id); $this->assertEquals($fakeResponse['data'][0]['name'], $templates[0]->name); - $this->assertEquals($fakeResponse['data'][0]['format'], $templates[0]->format); + $this->assertEquals($fakeResponse['data'][0]['format'], $templates[0]->format->value); $this->assertEquals($fakeResponse['data'][0]['version'], $templates[0]->version); $this->assertTrue(Carbon::parse($fakeResponse['data'][0]['updatedAt'], 'UTC')->eq($templates[0]->updatedAt)); Http::assertSent(function (Request $request) { return $request->hasHeader('X-Api-Key', 'foo') && $request->url( - ) === 'https://api.print.one/v1/templates?page=1&size=50'; + ) === 'https://api.print.one/v2/templates?page=1&limit=50'; }); } public function test_it_throws_exception_when_fetching_templates_fails() { Http::fake([ - 'https://api.print.one/v1/templates?*' => Http::response(status: Response::HTTP_INTERNAL_SERVER_ERROR), + 'https://api.print.one/v2/templates?*' => Http::response(status: Response::HTTP_INTERNAL_SERVER_ERROR), ]); $this->expectException(CouldNotFetchTemplates::class); $this->expectExceptionMessage('Something went wrong while fetching the templates from the Print.one API.'); - PrintOne::templates(page: 1, size: 50); + PrintOne::templates(page: 1, limit: 50); } public function test_it_can_order_a_card(): void @@ -133,51 +133,37 @@ public function test_it_can_order_a_card(): void 'billingId' => 'string', 'isBillable' => false, 'status' => 'order_created', + 'templateId' => 'tmpl_a8763477-2430-4034-880b-668604e61abb', + 'finish' => 'GLOSSY', 'format' => 'POSTCARD_A6', 'customerId' => '', 'createdAt' => '2022-10-06T08:49:40.368Z', 'updatedAt' => '2022-10-06T08:49:40.368Z', - 'pages' => [ - [ - 'id' => '90238dbd-623e-472a-892d-0ae7dccd5d57', - 'templateId' => 'tmpl_a8763477-2430-4034-880b-668604e61abb', - 'order' => 1, - 'cardId' => 'ord_25a36175-52c8-4c81-96fc-1d829af9ffee', - 'createdAt' => '2022-10-06T08:49:40.368Z', - 'updatedAt' => '2022-10-06T08:49:40.368Z', - ], - [ - 'id' => 'be52a381-8be8-4ccc-8c98-f73a53cf0d3b', - 'templateId' => 'tmpl_a8763477-2430-4034-880b-668604e61abb', - 'order' => 2, - 'cardId' => 'ord_25a36175-52c8-4c81-96fc-1d829af9ffee', - 'createdAt' => '2022-10-06T08:49:40.368Z', - 'updatedAt' => '2022-10-06T08:49:40.368Z', - ], - ], ]; Http::fake([ - 'https://api.print.one/v1/orders' => Http::response($fakeResponse), + 'https://api.print.one/v2/orders' => Http::response($fakeResponse), ]); - [$templateFront, $templateBack, $mergeVariables, $sender, $recipient] = $this->createOrder(); - - $postcard = new Postcard(front: $templateFront->id, back: $templateBack->id, format: $templateBack->format); + [$templateId, $finish, $mergeVariables, $sender, $recipient] = $this->createOrder(); $order = PrintOne::order( - $postcard, + templateId: $templateId, + finish: $finish, mergeVariables: $mergeVariables, sender: $sender, recipient: $recipient ); + //dd($order); + Http::assertSent( - fn(Request $request) => $request->url() === 'https://api.print.one/v1/orders' && - $request['pages'] == (object)["1" => $templateFront->id, "2" => $templateBack->id] && + // fn (Request $request) => dd($request) + fn (Request $request) => $request->url() === 'https://api.print.one/v2/orders' && + $request['templateId'] === $templateId && + $request['finish'] === $finish->value && $request['sender'] === $sender->toArray() && - $request['recipient'] === $recipient->toArray() && - $request['format'] === $templateFront->format + $request['recipient'] === $recipient->toArray() ); $this->assertInstanceOf(Order::class, $order); @@ -205,19 +191,19 @@ public function test_it_throws_exception_when_order_is_invalid(): void ]; Http::fake([ - 'https://api.print.one/v1/orders' => Http::response($fakeResponse, status: Response::HTTP_BAD_REQUEST), + 'https://api.print.one/v2/orders' => Http::response($fakeResponse, status: Response::HTTP_BAD_REQUEST), ]); - [$templateFront, $templateBack, $mergeVariables, $sender, $recipient] = $this->createOrder(); + [$templateId, $finish, $mergeVariables, $sender, $recipient] = $this->createOrder(); $this->expectException(CouldNotPlaceOrder::class); $this->expectExceptionMessage( "The order is invalid: 'tmpl_a8763477-2430-4034-880b-668604e61abb' has format: 'POSTCARD_A6' while you have provided: 'POSTCARD_A5'." ); - $postcard = new Postcard(front: $templateFront->id, back: $templateBack->id, format: $templateBack->format); PrintOne::order( - postcard: $postcard, + templateId: $templateId, + finish: $finish, mergeVariables: $mergeVariables, sender: $sender, recipient: $recipient @@ -227,17 +213,17 @@ public function test_it_throws_exception_when_order_is_invalid(): void public function test_it_throws_exception_when_placing_order_fails(): void { Http::fake([ - 'https://api.print.one/v1/orders' => Http::response(status: Response::HTTP_INTERNAL_SERVER_ERROR), + 'https://api.print.one/v2/orders' => Http::response(status: Response::HTTP_INTERNAL_SERVER_ERROR), ]); - [$templateFront, $templateBack, $mergeVariables, $sender, $recipient] = $this->createOrder(); + [$templateId, $finish, $mergeVariables, $sender, $recipient] = $this->createOrder(); $this->expectException(CouldNotPlaceOrder::class); $this->expectExceptionMessage('Something went wrong while placing the order in the Print.one API.'); - $postcard = new Postcard(front: $templateFront->id, back: $templateBack->id, format: $templateFront->format); PrintOne::order( - postcard: $postcard, + templateId: $templateId, + finish: $finish, mergeVariables: $mergeVariables, sender: $sender, recipient: $recipient @@ -246,13 +232,17 @@ public function test_it_throws_exception_when_placing_order_fails(): void public function test_it_can_fetch_template_previews(): void { - $imageString = file_get_contents(__DIR__ . '/images/card-preview.png'); + $imageString = file_get_contents(__DIR__.'/images/card-preview.png'); Http::fake([ - 'https://api.print.one/v1/templates/preview/*' => Http::response( - ['url' => 'https://api.print.one/v1/storage/template/preview/3c9d6b72-48a5-41f3-bcac-a5ffdd6eaede'] + 'https://api.print.one/v2/templates/preview/*' => Http::response( + [ + [ + 'url' => 'https://api.print.one/v2/storage/template/preview/3c9d6b72-48a5-41f3-bcac-a5ffdd6eaede', + ], + ] ), - 'https://api.print.one/v1/storage/template/preview/3c9d6b72-48a5-41f3-bcac-a5ffdd6eaede' => Http::response($imageString, 200, [ + 'https://api.print.one/v2/storage/template/preview/3c9d6b72-48a5-41f3-bcac-a5ffdd6eaede' => Http::response($imageString, 200, [ 'Content-type' => 'image/png', 'Content-Disposition' => 'attachment; filename=3c9d6b72-48a5-41f3-bcac-a5ffdd6eaede.png', ]), @@ -272,16 +262,20 @@ public function test_it_can_fetch_template_previews(): void $this->assertEquals($imageString, $previewImage); Http::assertSent( - fn(Request $request) => $request->url( - ) === 'https://api.print.one/v1/templates/preview/tmpl_a8763477-2430-4034-880b-668604e61abb/6' + fn (Request $request) => $request->url( + ) === 'https://api.print.one/v2/templates/preview/tmpl_a8763477-2430-4034-880b-668604e61abb/6' ); } public function test_it_throws_exception_when_fetching_preview_fails(): void { Http::fake([ - 'https://api.print.one/v1/templates/preview/*' => Http::response(['url' => 'https://api.print.one/v1/storage/template/preview/3c9d6b72-48a5-41f3-bcac-a5ffdd6eaede' ]), - 'https://api.print.one/v1/storage/template/preview/3c9d6b72-48a5-41f3-bcac-a5ffdd6eaede' => Http::response( + 'https://api.print.one/v2/templates/preview/*' => Http::response([ + [ + 'url' => 'https://api.print.one/v2/storage/template/preview/3c9d6b72-48a5-41f3-bcac-a5ffdd6eaede', + ], + ]), + 'https://api.print.one/v2/storage/template/preview/3c9d6b72-48a5-41f3-bcac-a5ffdd6eaede' => Http::response( status: Response::HTTP_INTERNAL_SERVER_ERROR ), ]); @@ -312,20 +306,19 @@ public function test_fake_client(): void ) ); - [$templateFront, $templateBack, $mergeVariables, $sender, $recipient] = $this->createOrder(); + [$templateId, $finish, $mergeVariables, $sender, $recipient] = $this->createOrder(); PrintOne::order( - $postcard = new Postcard( - front: $templateFront->id, back: $templateBack->id, format: $templateBack->format, - ), + templateId: $templateId, + finish: $finish, mergeVariables: $mergeVariables, sender: $sender, recipient: $recipient ); - PrintOne::assertOrdered($postcard, from: $sender, to: $recipient); + PrintOne::assertOrdered(templateId: $templateId, finish: $finish, from: $sender, to: $recipient); - PrintOne::preview($templateFront); - PrintOne::assertViewed($templateFront); + PrintOne::preview(template: $template); + PrintOne::assertViewed(template: $template); $templates = PrintOne::templates(1, 50); $this->assertInstanceOf(Collection::class, $templates); @@ -334,27 +327,29 @@ public function test_fake_client(): void public function test_it_can_fetch_an_order_preview(): void { - $contents = file_get_contents(__DIR__ . '/pdfs/order-preview.pdf'); + $contents = file_get_contents(__DIR__.'/pdfs/order-preview.pdf'); Http::fake([ - 'https://api.print.one/v1/storage/order/preview/*' => Http::response($contents, 200, [ - 'Content-type' => 'application/pdf', - 'Content-Disposition' => 'attachment; filename=ord_3c9d6b72-48a5-41f3-bcac-a5ffdd6eaede.pdf', - ]) - ] + 'https://api.print.one/v2/storage/order/preview/*' => Http::response($contents, 200, [ + 'Content-type' => 'application/pdf', + 'Content-Disposition' => 'attachment; filename=ord_3c9d6b72-48a5-41f3-bcac-a5ffdd6eaede.pdf', + ]), + ] ); PrintOne::previewOrder( order: $order = new Order( id: Str::uuid()->toString(), status: 'ready', + templateId: 'tmpl_a8763477-2430-4034-880b-668604e61abb', + finish: Finish::GLOSSY, createdAt: now(), isBillable: false ) ); Http::assertSent( - fn(Request $request) => $request->url() === "https://api.print.one/v1/storage/order/preview/{$order->id}" + fn (Request $request) => $request->url() === "https://api.print.one/v2/storage/order/preview/{$order->id}" ); } @@ -380,6 +375,8 @@ public function test_it_can_fetch_an_order(): void 'lastName' => 'Duck', 'firstName' => 'Donald', ], + 'templateId' => 'tmpl_a8763477-2430-4034-880b-668604e61abb', + 'finish' => 'GLOSSY', 'billingId' => 'string', 'isBillable' => false, 'status' => 'order_created', @@ -387,28 +384,10 @@ public function test_it_can_fetch_an_order(): void 'customerId' => '', 'createdAt' => '2022-10-06T08:49:40.368Z', 'updatedAt' => '2022-10-06T08:49:40.368Z', - 'pages' => [ - [ - 'id' => '90238dbd-623e-472a-892d-0ae7dccd5d57', - 'templateId' => 'tmpl_a8763477-2430-4034-880b-668604e61abb', - 'order' => 1, - 'cardId' => 'ord_25a36175-52c8-4c81-96fc-1d829af9ffee', - 'createdAt' => '2022-10-06T08:49:40.368Z', - 'updatedAt' => '2022-10-06T08:49:40.368Z', - ], - [ - 'id' => 'be52a381-8be8-4ccc-8c98-f73a53cf0d3b', - 'templateId' => 'tmpl_a8763477-2430-4034-880b-668604e61abb', - 'order' => 2, - 'cardId' => 'ord_25a36175-52c8-4c81-96fc-1d829af9ffee', - 'createdAt' => '2022-10-06T08:49:40.368Z', - 'updatedAt' => '2022-10-06T08:49:40.368Z', - ], - ], ]; Http::fake([ - 'https://api.print.one/v1/orders/ord_25a36175-52c8-4c81-96fc-1d829af9ffee' => Http::response($fakeResponse), + 'https://api.print.one/v2/orders/ord_25a36175-52c8-4c81-96fc-1d829af9ffee' => Http::response($fakeResponse), ]); $order = PrintOne::getOrder('ord_25a36175-52c8-4c81-96fc-1d829af9ffee'); @@ -423,21 +402,9 @@ public function test_it_can_fetch_an_order(): void private function createOrder(): array { - $templateFront = Template::fromArray([ - 'id' => 'tmpl_a8763477-2430-4034-880b-668604e61abb', - 'name' => 'voorkant', - 'format' => 'POSTCARD_A6', - 'version' => 6, - 'updatedAt' => '2022-09-27T14:48:00.514Z', - ]); + $templateId = 'tmpl_a8763477-2430-4034-880b-668604e61abb'; - $templateBack = Template::fromArray([ - 'id' => 'tmpl_a8763477-2430-4034-880b-668604e61abb', - 'name' => 'voorkant', - 'format' => 'POSTCARD_A6', - 'version' => 6, - 'updatedAt' => '2022-09-27T14:48:00.514Z', - ]); + $finish = Finish::GLOSSY; $sender = new Address( name: 'Nexibi', @@ -459,6 +426,6 @@ private function createOrder(): array 'content' => '