-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
INTEG-251: checkout find #64
Closed
JoeyDeHaas
wants to merge
5
commits into
feature/INTEG-263-body-to
from
feature/INTEG-251-checkout-find
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
9a9ca7c
INTEG-251: checkout find service
JoeyDeHaas d8b1516
INTEG-251: checkout show tests
JoeyDeHaas 074ff55
Apply php-cs-fixer changes
JoeyDeHaas e18bb10
INTEG-251: add checkout includes
JoeyDeHaas be832e6
Apply php-cs-fixer changes
JoeyDeHaas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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,32 @@ | ||
<?php | ||
|
||
namespace PlugAndPay\Sdk\Tests\Feature\Checkout\Mock; | ||
|
||
use PlugAndPay\Sdk\Tests\Feature\ClientMock; | ||
|
||
class CheckoutShowMockClient extends ClientMock | ||
{ | ||
public const BASIC_CHECKOUT = [ | ||
'id' => 1, | ||
'is_active' => true, | ||
'is_expired' => false, | ||
'name' => 'lorem-ipsum-test', | ||
'preview_url' => 'https://example.com/preview-url', | ||
'primary_color' => '#ff0000', | ||
'return_url' => 'https://example.com/return-url', | ||
'secondary_color' => '#00ff00', | ||
'slug' => 'lorem-ipsum-test', | ||
'url' => 'https://example.com/url', | ||
'created_at' => '2019-01-16T00:00:00.000000Z', | ||
'updated_at' => '2019-01-16T00:00:00.000000Z', | ||
'deleted_at' => '2019-01-16T00:00:00.000000Z', | ||
]; | ||
protected string $path; | ||
|
||
public function __construct(int $status = 200, array $data = []) | ||
{ | ||
parent::__construct($status, $data); | ||
|
||
$this->responseBody = ['data' => $data + self::BASIC_CHECKOUT]; | ||
} | ||
} |
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,66 @@ | ||
<?php | ||
|
||
namespace PlugAndPay\Sdk\Tests\Feature\Checkout; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use PlugAndPay\Sdk\Entity\Response; | ||
use PlugAndPay\Sdk\Exception\NotFoundException; | ||
use PlugAndPay\Sdk\Exception\UnauthenticatedException; | ||
use PlugAndPay\Sdk\Service\CheckoutService; | ||
use PlugAndPay\Sdk\Tests\Feature\Checkout\Mock\CheckoutShowMockClient; | ||
|
||
class ShowCheckoutTest extends TestCase | ||
{ | ||
/** @test */ | ||
public function it_should_throw_unauthorized_exception(): void | ||
{ | ||
$client = new CheckoutShowMockClient(status: Response::HTTP_UNAUTHORIZED); | ||
$service = new CheckoutService($client); | ||
$exception = null; | ||
|
||
try { | ||
$service->find(999); | ||
} catch (UnauthenticatedException $exception) { | ||
} | ||
|
||
static::assertEquals('Unable to connect with Plug&Pay. Request is unauthenticated.', $exception->getMessage()); | ||
} | ||
|
||
/** @test */ | ||
public function it_should_throw_not_found_when_checkout_not_found(): void | ||
{ | ||
$client = new CheckoutShowMockClient(status: Response::HTTP_NOT_FOUND); | ||
$service = new CheckoutService($client); | ||
$exception = null; | ||
|
||
try { | ||
$service->find(999); | ||
} catch (NotFoundException $exception) { | ||
} | ||
|
||
static::assertEquals('Not found', $exception->getMessage()); | ||
} | ||
|
||
/** @test */ | ||
public function it_should_return_basic_order(): void | ||
{ | ||
$client = new CheckoutShowMockClient(status: 200, data: ['id' => 1]); | ||
$service = new CheckoutService($client); | ||
|
||
$checkout = $service->find(1); | ||
|
||
static::assertSame(1, $checkout->id()); | ||
static::assertTrue($checkout->isActive()); | ||
static::assertFalse($checkout->isExpired()); | ||
static::assertSame('lorem-ipsum-test', $checkout->name()); | ||
static::assertSame('https://example.com/preview-url', $checkout->previewUrl()); | ||
static::assertSame('#ff0000', $checkout->primaryColor()); | ||
static::assertSame('https://example.com/return-url', $checkout->returnUrl()); | ||
static::assertSame('#00ff00', $checkout->secondaryColor()); | ||
static::assertSame('lorem-ipsum-test', $checkout->slug()); | ||
static::assertSame('https://example.com/url', $checkout->url()); | ||
static::assertSame('2019-01-16 00:00:00', $checkout->createdAt()->format('Y-m-d H:i:s')); | ||
static::assertSame('2019-01-16 00:00:00', $checkout->updatedAt()->format('Y-m-d H:i:s')); | ||
static::assertSame('2019-01-16 00:00:00', $checkout->deletedAt()->format('Y-m-d H:i:s')); | ||
} | ||
} |
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,18 @@ | ||
<?php | ||
|
||
namespace PlugAndPay\Sdk\Enum; | ||
|
||
enum CheckoutIncludes: string | ||
{ | ||
case CONFIRMATION = 'confirmation'; | ||
case CUSTOM_FIELDS = 'custom_fields'; | ||
case ORDER_BUMPS = 'order_bumps'; | ||
case POPUPS = 'popups'; | ||
case PRODUCT = 'product'; | ||
case PRODUCT_PRICING = 'product_pricing'; | ||
case SETTINGS = 'settings'; | ||
case STATISTICS = 'statistics'; | ||
case TEMPLATE = 'template'; | ||
case UPSELLS = 'upsells'; | ||
case WEBHOOKS = 'webhooks'; | ||
} |
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,38 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PlugAndPay\Sdk\Service; | ||
|
||
use PlugAndPay\Sdk\Contract\ClientInterface; | ||
use PlugAndPay\Sdk\Director\BodyTo\BodyToCheckout; | ||
use PlugAndPay\Sdk\Entity\Checkout; | ||
use PlugAndPay\Sdk\Enum\CheckoutIncludes; | ||
use PlugAndPay\Sdk\Exception\DecodeResponseException; | ||
use PlugAndPay\Sdk\Support\Parameters; | ||
|
||
class CheckoutService | ||
{ | ||
private ClientInterface $client; | ||
|
||
public function __construct(ClientInterface $client) | ||
{ | ||
$this->client = $client; | ||
} | ||
|
||
public function include(CheckoutIncludes ...$includes): self | ||
{ | ||
$this->includes = $includes; | ||
|
||
return $this; | ||
} | ||
|
||
/** @throws DecodeResponseException */ | ||
public function find(int $id): Checkout | ||
{ | ||
$query = Parameters::toString(['include' => $this->includes]); | ||
$response = $this->client->get("/v2/checkouts/$id$query"); | ||
|
||
return BodyToCheckout::build($response->body()['data']); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hoe kan je eigenlijk
->createdAt()->format('Y-m-d H:i:s')
doen, we hebben niks van carbon toch?